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. 这篇关于双到字符串转换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
08-20 23:49