gpt4 book ai didi

c++ - 将 `double` 转换为 `string`

转载 作者:塔克拉玛干 更新时间:2023-11-03 08:05:34 25 4
gpt4 key购买 nike

我正在实现这个:

double x;
ostringstream x_convert;
x_convert << x;
string x_str = x_convert.str();

好像有点多余。有没有更优雅的方式?

最佳答案

您使用的是 C++11 吗?如果是这样,则有:

auto x_str = std::to_string(x);

关于c++ - 将 `double` 转换为 `string`,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19690630/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com