直接编译不加参数会报错,要加 -std=c++0x
#include <iostream>
#include <string>
using namespace std;
int main()
{
string pi = "pi is " + std::to_string(3.1415926);
string perfect = to_string(1 + 2 + 4 + 7 + 14) + " is a perfect number";
cout << pi << '\n';
cout << perfect << '\n';
system("pause");
return 0;
}
g++ -std=c++0x tostring.cpp
参考:https://jingyan.baidu.com/article/b0b63dbf0746d94a483070bc.html