isstreamstream 头文件#include <sstream>

本文详细介绍了C++中使用标准库进行字符串输入和转换的方法,包括如何使用`printf`、`sprintf`、`stringstream`等工具进行高效操作。通过实例演示,帮助读者掌握字符串处理的基本技能。

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

http://blog.youkuaiyun.com/modiz/article/details/9464309

字符串一些输入和转换问题。

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <cmath>
#include <queue>
#include <map>
#include <stack>
#include <list>
#include <vector>
#include <sstream>
#define LL __int64
#define EPS 1e-8
using namespace std;
int main()
{
	double n=100;
	char s[1000];
	sprintf(s,"%lf",n);
	//cout<<s<<endl;
	string a="10000";
	stringstream stream;
	int m=0;
	stream<<a;
	stream>>m;
	cout<<m<<endl;
	stream.clear();
	stream.str("1 2 3.5");
	cout<<stream.str()<<endl;
	int q,w;double e;
	stream>>q;
	cout<<q<<endl;
	stream>>w;
	cout<<w<<endl;
	stream>>e;
	cout<<e<<endl;
	ostringstream ostr;
	ostr.str("abc");
	cout<<ostr.str()<<endl;
//如果构造的时候设置了字符串参数,那么增长操作的时候不会从结尾开始增加,
//而是修改原有数据,超出的部分增长
	ostr.put('d');
	ostr<<"efg";
	cout<<ostr.str()<<endl;
	stringstream ss("asd");
	cout<<ss.str()<<endl;
	ss.put('f');
	ss<<"gh";
	cout<<ss.str()<<endl;
	return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值