#include<iostream>
#include<sstream>
#include<string>
using namespace std;
int main( void )
{
int i = 12345;
stringstream s;//流格式化符,把int转化为string
s << i;
string str = s.str(); //等到string类型的字符串
cout << str << endl;
const size_t BUF_SIZE = 8;
char buf[BUF_SIZE];
strcpy( buf, str.c_str( ));
cout << buf << endl; //等到C语言风格(C-style)的字符串
system( "PAUSE" );
return EXIT_SUCCESS;
}
/*-----------
12345
12345
请按任意键继续. . .
-----------------------*/
stringstream流格式化符,把int转化为string,string又可以转为C语言风格的字符串
最新推荐文章于 2024-06-18 13:37:06 发布