c++ stringstream

yezeguo 2008-12-14 10:23:22
怎么利用stringstream把字符串"watashi:"really? this fact is amazing~~""(不包括最外面的引号)中的单词都提取出来,谢谢!
...全文
139 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
yezeguo 2008-12-30
  • 打赏
  • 举报
回复
谢谢啊,发了这个帖子之后就没留意了,对不起大家了
SearchLife 2008-12-14
  • 打赏
  • 举报
回复
#include <iostream>
#include <sstream>
#include <string>
using namespace std;


int main( void )
{
string str = "watashi:\"really? this fact is amazing~~\"";
cout << str <<endl;
int i =0;
while (str[i])
{
if (!((str[i] >= 'a' && str[i] <= 'z') || (str[i] >= 'A' && str[i] <= 'Z')))
{
str[i] = ' ';
}
i++;
}

stringstream ss(str);
string s;
while (ss >> s)
{
cout << s <<endl;
}

return 0;
}

调试通过
codejian 2008-12-14
  • 打赏
  • 举报
回复
LZ的意思是说 提取这句话中出现的单词,其他符号都过滤掉是吧?
SeanHwang 2008-12-14
  • 打赏
  • 举报
回复
括号?是引号吧?
Vegertar 2008-12-14
  • 打赏
  • 举报
回复
楼主说清楚点吧,你想要个什么效果?
就呆在云上 2008-12-14
  • 打赏
  • 举报
回复
#include <iostream> 
#include <sstream>
#include <string>
using namespace std;


int main( void )
{
string str = "watashi:\"really? this fact is amazing~~\"";
stringstream ss(str);
cout << ss.rdbuf();
return 0;
}


输出:
watashi:"really? this fact is amazing~~"
herman~~ 2008-12-14
  • 打赏
  • 举报
回复
MARK

64,642

社区成员

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

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