Linux 拨号vps windows公众号手机端

c++中float转string怎么实现

lewis 9年前 (2016-12-27) 阅读数 7 #程序编程
文章标签 c++

在C++中,可以使用std::to_string()函数将float类型转换为string类型,示例如下:

#include <iostream>
#include <string>

int main() {
    float number = 3.14f;
    std::string str = std::to_string(number);
    
    std::cout << "Float number: " << number << std::endl;
    std::cout << "String representation: " << str << std::endl;
    
    return 0;
}

运行该程序,输出结果为:

Float number: 3.14
String representation: 3.140000
版权声明

本文仅代表作者观点,不代表米安网络立场。

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

热门