首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

运行出现异常

2012-08-30 
运行出现错误请教,哪里错了。#includeiostream#includestringusing namespace stdint main(){string t

运行出现错误
请教,哪里错了。
#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;
}

[解决办法]
如果是char数组的话 可以这样赋值 char w[max_word]={0};


[解决办法]
0是int string的构造函数没有用一个int 或者一个 char类型的变量来进行构造的。
换成{""}之类的可以。

热点排行