麻烦各位大侠帮我看一下,到底哪里出错了?为什么会有warning?
下面是我写的代码,但是总是出现warning,麻烦各位给小弟一些意见。
//编写一个程序来计算在它的输入中每个不同的单词所出现的个数
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
using namespace std;
int main()
{
//提示用户输入
cout < < "Please enter the word " < <endl;
vector <string> wordlist;
string word;
while (cin> > word)
{
wordlist.push_back(word);
}
//将输入的单词进行排序
sort (wordlist.begin(),wordlist.end());
//检查wordlist 为空
typedef vector <string> ::size_type vec_sz;
vec_sz size=wordlist.size();
if (size==0)
{
cout < <endl < < "You must enter some words. " < <endl;
return 1;
}
//对不同的单词进行统计并输出
for (int i=0;i <=wordlist.size();i++)
{int sum;
if (wordlist[i] == wordlist[i++])
{sum++; }
else
{
cout < <wordlist[i] < < " " < <sum < <endl;
sum = 0;
}
}
return 0;
}
[解决办法]
VC6编译器兼容性的问题,最少MS官方文档中建议不理他,把warning C4786直接关掉就行了
添上这一行:
#pragma warning(disable: 4786)