C++sstream

本文详细介绍了如何使用C++中的stringstream进行字符串流的操作,包括数据的写入和读取,以及如何转换不同数据类型。并通过实例展示了如何利用stringstream处理整数与字符串之间的转换。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

#include <iostream>
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<cstring>
#include<sstream>
#include<strstream>
#include<queue>
using namespace std;


int main()
{
	int a = 520;
	int b = 521;
	stringstream ss;
	string str;
	ss << "a= " << a << '\n';//"a= "此处有空格,字符串流是通过空格判断一个字符串的结束
	ss << "b= " << b;//  每个都输入;
	cout <<"ss="<<ss.str() << endl;
	
	
	//如果一次直接按如str中,即
	ss>>str;
	ss>>str;
	//会直接替换str

	//提取520 521保存为int 类型,当然c d 声明为string类型 ,那么这俩个字面常量相应的保存为string类型
	int c, d;
	string s;
	ss >> s >> c >> s >> d;
	cout << c << "  " << d << endl;
	ss.str(" ");
	cout << "SS="<<ss.str() << endl;

	

	return 0;

}

https://jingyan.baidu.com/article/d3b74d643657d61f77e6092e.html
https://blog.csdn.net/Wchenchen0/article/details/81356489#commentBox

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值