istringstream用法 关于字符串处理的问题

来源:互联网 发布:南宁广电网络上网 编辑:程序博客网 时间:2024/06/08 10:07

istringstream对象可以绑定一行字符串,然后以空格为分隔符把该行分隔开来。

程序举例:

#include <iostream>#include <sstream>#include <string>using namespace std;int main(){string str1,str2;while(getline(cin,str2)){//getline()函数接受一个字符串,其中可以有空格   istringstream stream(str2);   cout<<str2<<endl;   while(stream >> str1)   cout<< str1.c_str()<<endl;}return 0;}
昨天比赛时一道很水的题目就因为字符串处理不会,结果写了一个半小时才过,看来以后要做一些字符串处理的题目了,各种问题,各种弱爆了,,,,,

原创粉丝点击