c++如何在字符串中放入双精度
c++ How to put a double into a String
在java中,使用字符串可以完成以下操作:
int stuff;
string otherstuff;
otherstuff = "I like this much stuff: " + stuff;
但在C++中,我不知道如何操作。
在C++11中:
otherstuff = "I like this much stuff: " + std::to_string(stuff);
历史上(有时在C++11中仍然有用):
std::ostringstream ss;
ss << "I like this much stuff: " << stuff;
otherstuff = ss.str();
我喜欢使用字符串流来处理这样的事情。
std::stringstream ss;
double dub = 3.14159254;
ss << dub;
std::string s = ss.str();
同样值得注意的是boost::lexical_cast<std::string>(stuff)
。如果由于某种原因您不能使用C++11
相关文章:
- 如何在C++中的同一函数中使用字符串和双精度
- C 字符串返回字符串的整数/双精度/长整型值
- 如何从字符串转换为双精度*
- C++如何将字符串逐行转换为双精度
- 如何在 C++ 中将双精度数组中的值"force convert"到字符串输出中?
- 在C++中将字符串转换为双精度,而无需科学记数法
- 使用从文件(stod、strtod、atof)中提取的数据C++从字符串转换为双精度.csv
- 如何在C++中将字符串转换为双精度?
- 将双精度值转换为 char 变量时字符串流如何工作
- 在 c++ 中从双精度转换为字符串
- 从字符串转换为双精度和整数 - C++
- 如何从char16_t字符串文字中读取双精度?
- 分析字符串中的双精度和单词
- 使用 sprintf 和 %g 将双精度转换为字符串的意外结果
- C++将包含非人类可读数据的字符串转换为 200 双精度
- 将大双精度转换为科学记数法以用作字符串?
- 字符串和双精度的麻烦,等值后再得到一个数字
- 如何从字符串流中提取双精度
- 如何调用返回双精度或字符串并将其保存在地图上但作为对象的类的方法
- 在C++中使用atof将带小数的字符串转换为双精度字符串