“to_string”不是“std”的成员? [英] "to_string" isn't a member of "std"?

查看:1516
本文介绍了“to_string”不是“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 现在。

这篇关于“to_string”不是“std”的成员?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆