运行出现错误

fpkoko 2012-07-03 09:46:35
请教,哪里错了。
#include<iostream>
#include<string>
using namespace std;
int main(){
string text;
const string sep=",.\"\n ";
const int max_word=100;
string word[max_word]={0};
cout<<"请输入一段话(以#结束):";
getline(cin,text,'#');
int start=text.find_first_not_of (sep);
int end=0;
int word_count=0;
while(start!=string::npos&&word_count<max_word)
{
end=text.find_first_of(sep,start+1);
if(end==string::npos)
end=text.length();
word[word_count]=text.substr(start,end-start);
start=text.find_first_not_of(sep,end+1);
word_count++;
}
for(int i=0;i<=word_count;i++)
cout<<word[i]<<endl;
return 0;
}
...全文
107 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
tongzhipeng5699 2012-07-03
  • 打赏
  • 举报
回复
0是int string的构造函数没有用一个int 或者一个 char类型的变量来进行构造的。
换成{""}之类的可以。
恨天低 2012-07-03
  • 打赏
  • 举报
回复
使用vector<string> vs
wZi 2012-07-03
  • 打赏
  • 举报
回复
呵呵。我也发生过这种情况。发帖后自己又解决了
帅得不敢出门 2012-07-03
  • 打赏
  • 举报
回复
如果是char数组的话 可以这样赋值 char w[max_word]={0};

fpkoko 2012-07-03
  • 打赏
  • 举报
回复
自己找到了。

string word[max_word]={0};
应该是
string word[max_word];

33,311

社区成员

发帖
与我相关
我的任务
社区描述
C/C++ 新手乐园
社区管理员
  • 新手乐园社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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