在C++中,可以使用std::to_string()
函數(shù)將float
類型轉(zhuǎn)換為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;
}
運行該程序,輸出結(jié)果為:
Float number: 3.14
String representation: 3.140000