命名空间std的秘密

99.99%的人都认为命名空间std是C++系统自带的

直到我在编译代码时突然报错了

代码如下:

#include
using namespace std;
int main()
{
    char words[105][55], tword[55], temp[55];//二维数组保存多个单词 
	int ti = 0, wi = 0;//t_i:tword中的下标 w_i:words中的下标 
    char s[10005];
	cin.getline(s, 10005);
	int len = strlen(s);
	for(int i = 0; i <= len; ++i)//解析整个字符串 
	{
		if(s[i] >= 'a' && s[i] <= 'z' || s[i] >= 'A' && s[i] <= 'Z')//如果是字母 
			words[wi][ti++] = s[i];//wi单词添加字母s[i] 
		else//如果是空格或'\0' 
		{
		    if(ti == 0)//如果没有添加字母,那么可能是遇到连续的空格,不添加单词 
                continue;
			words[wi++][ti] = '\0';//把words[wi]构成一个字符串
			ti = 0;
			for(int j = wi-1; j >= 1; --j)//插入排序 
			{
				if(strcmp(words[j], words[j-1]) < 0)//如果右面单词的比左面的小 
				{//交换两个字符串 
					strcpy(temp, words[j]);
					strcpy(words[j], words[j-1]);
					strcpy(words[j-1], temp);
				}
				else
					break;
			}
		}
	}
	strcpy(temp,"");//用temp保存上一个取到的单词 
	for(int i = 0; i < wi; ++i)
	{
		if(strcmp(words[i], temp) != 0)
		{
			cout << words[i] << endl;
			strcpy(temp, words[i]);
		}
	}
	return 0;
}

当时正在写一道题,是给输入的单词排序

突然报错了

你可能感兴趣的:(算法,数据结构)