请问istringstream的用法

mmosquito 2005-12-22 01:54:23
istringstream is("hello world");
string s,str;
str = is.str() ; //str = hello world
is >> s; //s = hello
str = is.str() ; //str = hello world why not str = world?

而我期望最后str = world
怎么实现?
...全文
240 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
JOKER_UFO 2005-12-22
  • 打赏
  • 举报
回复
我在里面找到了一个函数可取出你要的东西:
#include<istream>
#include<sstream>
#include<string.h>
#include<iostream>
#include<ostream>
using namespace std;
int main()
{
istringstream is("hello world");
string s,str,k;
str = is.str() ; //str = hello world
is >>s; //s = hello
//k = str - s;
cout<<str<<endl;
cout<<s<<endl;
cout<<k<<endl;
cout<<is.rdbuf()<<endl;//得到后面的字符串
return 0;
}
sinall 2005-12-22
  • 打赏
  • 举报
回复
小弟这块学的不好。说错勿怪。

#include <iostream>
#include <vector>
#include <sstream>
using namespace std;

int main()
{
istringstream is("hello world hello sinall");
string s,str;
str = is.str() ; //str = hello world
is >> s; //s = hello
vector<char> vc(100);
long cur = is.tellg();
long size = is.rdbuf()->pubseekoff(0, ios::end, ios::in);
is.rdbuf()->pubseekpos(cur, ios::in);
is.read(&vc[0], size-cur);
cout << &vc[0] << endl;
}
mmosquito 2005-12-22
  • 打赏
  • 举报
回复
to sinall
ok..
istringstream is("hello world hello sinall" );
string s,str;
str = is.str() ;
is >> s; //s = hello
how to get the rest "world hello sinall" ?
lyn10155 2005-12-22
  • 打赏
  • 举报
回复
我也不懂
sinall 2005-12-22
  • 打赏
  • 举报
回复
istringstream is("hello world");
string s,str;
str = is.str() ; //str = hello world
is >> s; //s = hello
is >> str;
iamcaicainiao 2005-12-22
  • 打赏
  • 举报
回复
关注,这个istringstream是什么咚咚我还不清楚呢
iamcaicainiao 2005-12-22
  • 打赏
  • 举报
回复
xianshiqi 2005-12-22
  • 打赏
  • 举报
回复
学习

64,648

社区成员

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

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