双到字符串转换 [英] Double to string conversion

查看:75
本文介绍了双到字符串转换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,


有没有办法将double值转换为字符串。我知道那里

是fcvt(),但我认为这个函数不是标准的

库的一部分。如果可能,我想要标准。


我想要做的是将一个double值转换为一个字符串

,包含8个元素。由于我使用的文件,8是固定的。我将

用文件中的一个(8个字符串)更改这个8个字符的字符串

,依此类推。但我必须先进行转换。


任何帮助将不胜感激,


提前致谢。

推荐答案

#include< sstream>

#include< iomanip>

#include< iostream>


使用命名空间std;

stringstream文字;

double Somevalue = 9.987654;


文字<< Somevalue;


cout<< Text.str()<<结束;


// TODO:查找iomanip的东西以获得你想要的格式

-

问候,Ron AF格雷夫

http://moonlit.xs4all.nl


" utab" <微米******** @ gmail.com>在消息中写道

新闻:11 ********************** @ i39g2000cwa.googlegr oups.com ...
#include <sstream>
#include <iomanip>
#include <iostream>

using namespace std;
stringstream Text;
double Somevalue = 9.987654;

Text << Somevalue;

cout << Text.str() << endl;

// TODO: Lookup the iomanip stuff to get the format you want
--
Regards, Ron AF Greve

http://moonlit.xs4all.nl

"utab" <um********@gmail.com> wrote in message
news:11**********************@i39g2000cwa.googlegr oups.com...
你好,

有没有办法将double值转换为字符串。我知道那里有
是fcvt(),但我认为这个函数不是标准库的一部分。如果可能,我想要标准。

我想要做的是将一个double值转换为一个包含8个元素的字符串
。由于我使用的文件,8是固定的。我将
用文件中的一个(8个字符串)更改这8个字符串,依此类推。但我必须先进行转换。

任何帮助将不胜感激,

提前致谢。
Hi there,

Is there a way to convert a double value to a string. I know that there
is fcvt() but I think this function is not a part of the standard
library. I want sth from the standard if possible.

The thing I am trying to do is to convert a double value to a string
with 8 elements. 8 is fixed because of the files I work with. I will
change this 8 character string with the one(8 character string) already
in the file and so on. But I have to do the conversion first.

Any help will be appreciated,

Thanks in advance.


utab skrev:
utab skrev:
你好,

有没有办法将double值转换为字符串。我知道那里有
是fcvt(),但我认为这个函数不是标准库的一部分。如果可能,我想要标准。

我想要做的是将一个double值转换为一个包含8个元素的字符串
。由于我使用的文件,8是固定的。我将
用文件中的一个(8个字符串)更改这8个字符串,依此类推。但我必须先进行转换。

任何帮助将不胜感激,

提前致谢。
Hi there,

Is there a way to convert a double value to a string. I know that there
is fcvt() but I think this function is not a part of the standard
library. I want sth from the standard if possible.

The thing I am trying to do is to convert a double value to a string
with 8 elements. 8 is fixed because of the files I work with. I will
change this 8 character string with the one(8 character string) already
in the file and so on. But I have to do the conversion first.

Any help will be appreciated,

Thanks in advance.




#include< sstream>

#include< string>


模板< typename T>

std :: string AnyToString(T t){

std :: ostringstream sstrm;

sstrm<< t;

返回sstrm.str();

}


-

TB @ SWEDEN



#include <sstream>
#include <string>

template<typename T>
std::string AnyToString(T t) {
std::ostringstream sstrm;
sstrm << t;
return sstrm.str();
}

--
TB @ SWEDEN


Thx用于快速回复Moonlit。

Thx for the quick reply Moonlit.


这篇关于双到字符串转换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆