#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
最新推荐文章于 2025-04-12 23:06:40 发布
本文介绍如何使用C++中的stringstream类将double类型的数据转换为string类型,并通过C-style字符串输出。示例代码包括声明stringstream对象、将double赋值给对象、获取转换后的string以及使用C-style字符串进行输出。
2224

被折叠的 条评论
为什么被折叠?



