程序有问题,赶紧来看看,死循环了。

najiushifeng3 2007-06-25 12:15:27
#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;
}
...全文
136 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
taodm 2007-06-25
  • 打赏
  • 举报
回复
你是不知道怎么结束输入吧。
回车-Ctrl_z/F6-回车结束输入。
healer_kx 2007-06-25
  • 打赏
  • 举报
回复
sf是什么意思啊?:
healer_kx 2007-06-25
  • 打赏
  • 举报
回复
sf
isarc 2007-06-25
  • 打赏
  • 举报
回复
sf
PEPSI_COLA 2007-06-25
  • 打赏
  • 举报
回复
for (int i=0;i<=wordlist.size();i++) //这里越界访问了

64,639

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧