我是新手。我刚刚在终端运行我编写的 C++ 程序时出错:error: ‘stoi’ is not a member of ‘std’
。他们告诉我编译器太旧了。
我正在使用 Ubuntu 14.04。
我的g++版本是4.8.4。
我如何升级?
答案1
您不需要升级。指定标准版本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