在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