Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

Okay, so I have

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);
     ^

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
204 views
Welcome To Ask or Share your Answers For Others

1 Answer

you may want to specify the C++ version with

g++ -std=c++11 tmp.cpp -o tmp

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

At least gcc 4.9.2 I believe also support part of C++14 by specifying

g++ -std=c++1y tmp.cpp -o tmp

Update: gcc 5.3.0 (I am using the cygwin version) supports both -std=c++14 and -std=c++17 now.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...