#include<iostream>
#include<sstream>
#include<string>
using namespace std;
int main( void )
{
double i = 12.345;
stringstream s;//流格式化符,把double转化为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;
}
/*-----------
12.345
12.345
请按任意键继续. . .
-----------------------*/
stringstream把double转化为string
最新推荐文章于 2022-11-08 12:41:16 发布