64,654
社区成员
发帖
与我相关
我的任务
分享
vector<string> vstr;
string src_str = "this is my world!hello,my world!";
string temp_str;
int cur_pos = 0;
int pos = 0;
//标点替换空格
while(1)
{
if(ispunct(src_str[cur_pos]))
{
src_str = src_str.replace(cur_pos,1,1,' ');
}
if(cur_pos++ == src_str.length())
break;
}
cur_pos = 0;
//遇到空格切割
while(1)
{
pos = src_str.find(' ',cur_pos);
if(pos == string::npos)
break;
temp_str = src_str.substr(cur_pos,pos - cur_pos);
cur_pos = (pos + 1);
printf("pos:%d cur:%d",pos,cur_pos);
vstr.push_back(temp_str);
}