各位c++高手们!怎么把double型转为string,不要转为char

msy2518 2008-10-23 10:46:28
如题!
各位高手最好能把所用的函数的头文件写出来
我是新手知道的不是很多。呵呵多多照顾一下了
...全文
563 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
frisky_lobo 2008-10-25
  • 打赏
  • 举报
回复
_ecvt(...),_gcvt(...),_fcvt(...)
OenAuth.Net 2008-10-25
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 lzr4304061988012 的回复:]
C/C++ code
#include <iostream>
#include <sstream>
#include <string>
using namespace std;

void main()
{
double d=12.3456;
ostringstream oss;
oss<<12.3456;

string str(oss.str());

cout<<str<<endl;
}
[/Quote]

正解,刚刚看到邮件通知说没人回复,LS太快了
lzr4304061988012 2008-10-25
  • 打赏
  • 举报
回复

#include <iostream>
#include <sstream>
#include <string>
using namespace std;

void main()
{
double d=12.3456;
ostringstream oss;
oss<<12.3456;

string str(oss.str());

cout<<str<<endl;
}
太乙 2008-10-25
  • 打赏
  • 举报
回复
纯属接分~
fallening 2008-10-25
  • 打赏
  • 举报
回复
#include <boost/lexical_cast.hpp>

double d;
string s = lexical_cast<string>(d);


msy2518 2008-10-25
  • 打赏
  • 举报
回复
等了好久了,终于有回复了
谢谢各位大侠了
  • 打赏
  • 举报
回复
memcpy

format

+=

..................
xxgamexx 2008-10-25
  • 打赏
  • 举报
回复

#include <sstream>
#include <string>
using namespace std;
int main(int argc,char *argv[])
{
double i=3.5555;
stringstream stream;
string str;
stream<<i;
stream>>str;
return 0;
}

65,211

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧