“to_string"不是“std"的成员吗? [英] "to_string" isn't a member of "std"?
问题描述
好的,我有
tmp.cpp:
#include <string>
int main()
{
std::to_string(0);
return 0;
}
但是当我尝试编译时,我得到:
But when I try to compile I get:
$ 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).
I'm running g++ version 4.8.1. Unlike all the other references to this error that I found out there, I am not using MinGW, I'm on Linux (3.11.2).
任何想法为什么会发生这种情况?这是标准行为,我做错了什么还是某处有错误?
Any ideas why this is happening? Is this standard behaviour and I did something wrong or is there a bug somewhere?
推荐答案
你可能想要指定 C++ 版本
you may want to specify the C++ version with
g++ -std=c++11 tmp.cpp -o tmp
我手头没有 gcc 4.8.1,但在旧版本的 GCC 中,你可以使用
I don't have gcc 4.8.1 at hand , but in older versions of GCC, you can use
g++ -std=c++0x tmp.cpp -o tmp
至少 gcc 4.9.2 我相信通过指定也支持 C++14 的一部分
At least gcc 4.9.2 I believe also support part of C++14 by specifying
g++ -std=c++1y tmp.cpp -o tmp
更新:gcc 5.3.0(我用的是cygwin版本)现在支持-std=c++14
和-std=c++17
.
Update:
gcc 5.3.0 (I am using the cygwin version) supports both -std=c++14
and -std=c++17
now.
这篇关于“to_string"不是“std"的成员吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!