社区
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
怎么实现?
...全文
278
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写文章
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
打赏
举报
回复
学习
C++中的i
stringstream
的
用法
i
stringstream
是一个比较有用的c++的输入输出控制类。 C++引入了o
stringstream
、i
stringstream
、
stringstream
这三个类,要使用他们创建对象就必须包含这个头文件。 i
stringstream
类用于执行C++风格的串流的输入操作。 o
stringstream
类用于执行C风格的串流的输出操作。 strstream类同时可以支持C风格的串流的输
i
stringstream
的
用法
i
stringstream
是 C++ 标准库
提供的输入字符串流(类似 cin),用于 解析字符串 并提取数据。
C++中i
stringstream
的简单
用法
C++98中std::i
stringstream
的构造函数是 explicit i
stringstream
(const string& str, ios_base::openmode which = ios_base::in); (默认构造函数,已经其他构造函数这里省略,只列举经常用到的构造函数) cplusplus上的文档 第一个参数是const string& str 可以通过const string& str对istrings
C++ i
stringstream
用法
i
stringstream
是将字符串变成字符串迭代器一样,将字符串流在依次拿出,因为它不会将空格作为流。这样就实现了字符串的空格切割。
用法
例题: #include <iostream> #include <stdio.h> #include <string.h> #include <set> #include <sstream> using namespace std; int main() { string str1,str2
i
stringstream
的
用法
今天看到了一个比较有用的c++的输入输出控制类。C++引入了o
stringstream
、i
stringstream
、
stringstream
这三个类,要使用他们创建对象就必须包含这个头文件。 i
stringstream
类用于执行C++风格的串流的输入操作。 o
stringstream
类用于执行C风格的串流的输出操作。 strstream类同时可以支持C风格的串流的输入输出操作。 ist
C++ 语言
65,213
社区成员
250,514
社区内容
发帖
与我相关
我的任务
C++ 语言
C++ 语言相关问题讨论,技术干货分享,前沿动态等
复制链接
扫一扫
分享
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++
技术论坛(原bbs)
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
请不要发布与C++技术无关的贴子
请不要发布与技术无关的招聘、广告的帖子
请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下
试试用AI创作助手写篇文章吧
+ 用AI写文章