C++格式化输入输出

#include <sstream>
#include <iomanip>

std::stringstream  strstream1,strstream2,strstream3,strstream4,strstream5;
strstream1 << std::setw(5) << std::setfill('0') << 5;//"00005"
strstream2 << std::hex << 16;//"10",std::dec or std::otc
int value;
strstream2 >> std::hex >> value;//value = 16
strstream3 << "0xFF";
strstream3 >> std::hex >> value;//value =255;没有std::hex value = 0

strstream4 << std::fixed << std::setprecision(3) << 33.1415;//"33.142"
strstream5 << std::showpoint << 3.;//"3.0000"


//stringstream可用于算数类型和字符串之间转换,同时c++11也新增函数用于转换
std::string       str = std::to_string(41);
int                v1 = std::atoi("10");
long               v2 = std::atol("10");
unsigned long      v3 = std::atoul("10");
long long          v4 = std::atoll("10");
unsigned long long v5 = stoull("10");
folat              v6 = stof("0.12");
double             v7 = stod("0.12");
long double        v8 = stold("0.3333");

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值