社区
C++ 语言
帖子详情
请问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
怎么实现?
...全文
246
8
打赏
收藏
请问istringstream的用法
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 怎么实现?
复制链接
扫一扫
分享
转发到动态
举报
AI
作业
写回复
配置赞助广告
用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
打赏
举报
回复
学习
Stringstream
的
用法
c++
c++中
stringstream
的
用法
i
stringstream
, o
stringstream
,
stringstream
用法
示例
2025年sting流:i
stringstream
,o
stringstream
,
stringstream
。教会你str()和clear()的区别_stream.zip
掌握i
stringstream
、o
stringstream
和
stringstream
的正确使用方法,以及理解str()和clear()方法的差异,对于成为一名优秀的C++开发者至关重要。随着技术的发展,这些基本工具的重要性不会减少,反而会因为它们的便捷...
C++中
stringstream
的
用法
和实例
之前在leetcode中进行string和int的转化时使用过i
stringstream
,现在大致总结一下
用法
和测试用例。 介绍:C++引入了o
stringstream
、i
stringstream
、
stringstream
这三个类,要使用他们创建对象就必须包含sstream.h...
C++风格的几种IO流
比如调用i
stringstream
的.clear()成员函数来清除错误标志,以便于可以重新使用i
stringstream
对象。 通过以上的介绍,我们可以看到i
stringstream
、o
stringstream
和
stringstream
在处理字符串流数据方面提供了极大的...
利用C++实现从std::string类型到bool型的转换
总之,在C++中,将`std::string`转换为`bool`涉及到对字符串内容的理解以及`std::i
stringstream
`的正确使用。在实际应用中,根据输入数据的格式,可能需要灵活地选择合适的转换策略,以确保程序的健壮性和可维护性。...
C++ 语言
65,187
社区成员
250,526
社区内容
发帖
与我相关
我的任务
C++ 语言
C++ 语言相关问题讨论,技术干货分享,前沿动态等
复制链接
扫一扫
分享
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++
技术论坛(原bbs)
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
请不要发布与C++技术无关的贴子
请不要发布与技术无关的招聘、广告的帖子
请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下
试试用AI创作助手写篇文章吧
+ 用AI写文章