#include<bits/stdc++.h>
using namespace std;
int main(){
string s ;
int num= 34 ;
stringstream ss;//内存字符串
ss << setw(8) << setfill('0') << num << endl;//按八位补其前导零
s = ss.str();//转换常规字符串
cout << s;
//用法二
int a = 12;
int b = 20;
char f = 'x';
string d = "hello" ;
stringstream ss1;
ss1 << a << " " << b << " " << f << " " << d;
cout << ss1.str() << endl;
//用法三:序列化
int aa;
int bb;
char ff;
string dd;
ss1 >> aa >> bb >> ff >> dd;
cout << aa << bb << ff << dd;
return 0;
}
—— 本文来自火龙信奥(义乌睿码科技):义乌青少年信息学奥赛与编程教育平台,专注 CSP-J/S、NOIP、GESP 竞赛培训,线上线下融合教学,助力编程升学。网址:hlcoding.com