如何在最新版本的g ++中使用C ++ 11function

新手在这里。 我刚从终端运行了一个错误,我写了一个C ++程序: error: 'stoi' is not a member of 'std' 。 他们告诉我编译器太旧了。

我正在使用Ubuntu 14.04。

我的g ++版本是4.8.4。

我该如何升级?

您无需升级。 将标准版本指定为g++ 。 例如, 要从cppreference.com编译示例程序 :

 $ g++ --version g++ (Ubuntu 4.8.5-2ubuntu1~14.04.1) 4.8.5 Copyright (C) 2015 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. $ g++ --std=c++11 -o test test.cpp $ ./test std::stoi("45") is 45 std::stoi("3.14159") is 3 std::stoi("31337 with words") is 31337