好的,我有
tmp.cpp:
#include <string>
int main()
{
std::to_string(0);
return 0;
}
但是当我尝试编译时,我得到:
$ g++ tmp.cpp -o tmp
tmp.cpp: In function ‘int main()’:
tmp.cpp:5:5: error: ‘to_string’ is not a member of ‘std’
std::to_string(0);
^
我正在运行 g++ 版本 4.8.1。与我在那里发现的所有其他对这个错误的引用不同,我没有使用 MinGW,我使用的是 Linux (3.11.2)。
任何想法为什么会发生这种情况?这是标准行为,我做错了什么还是某处有错误?
最佳答案
您可能需要指定 C++ 版本
g++ -std=c++11 tmp.cpp -o tmp
我手头没有 gcc 4.8.1,但在旧版本的 GCC 中, 你可以使用
g++ -std=c++0x tmp.cpp -o tmp
至少 gcc 4.9.2 我相信通过指定也支持 C++14 的一部分
g++ -std=c++1y tmp.cpp -o tmp
更新:
gcc 5.3.0(我用的是cygwin版本)现在支持-std=c++14
和-std=c++17
。
关于c++ - "to_string"是 't a member of "标准”?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19122574/