C++ 各种类型转string
程序员文章站
2022-03-05 12:58:23
...
以下内容来自cplusplus.com
// to_string example
#include <iostream> // std::cout
#include <string> // std::string, std::to_string
int main ()
{
std::string pi = "pi is " + std::to_string(3.1415926);
std::string perfect = std::to_string(1+2+4+7+14) + " is a perfect number";
std::cout << pi << '\n';
std::cout << perfect << '\n';
return 0;
}
pi is 3.141593 28 is a perfect number
推荐阅读