在过去的几个月里,我一直在学习C++和使用终端.我的代码使用g ++和C++ 11编译并运行良好,但在最近几天它开始出错并且我在编译时遇到了问题.我可以编译和运行的唯一程序取决于较旧的C++标准.
我首先得到的错误与头文件中的#include <array>有关.不知道为什么会这样,但我通过使用boost/array来解决它.我无法解决的另一个错误是使用std :: stoi.array和stoi都应该在C++ 11标准库中.我做了以下简单的代码来演示正在发生的事情:
//
// stoi_test.cpp
//
// Created by ecg
//
#include <iostream>
#include <string> // stoi should be in here
int main() {
std::string test = "12345";
int myint = std::stoi(test); // using stoi, specifying in standard library
std::cout << myint << '\n'; // printing the integer
return(0);
}
Run Code Online (Sandbox Code Playgroud)
尝试使用ecg $ g ++编译-o stoi_trial stoi_trial.cpp -std = c ++ 11
array.cpp:13:22:错误:命名空间'std'中没有名为'stoi'的成员; 你是说'ati'吗?int myint = std :: stoi(test); ~~~~~ ^ ~~~ atoi /usr/include/stdlib.h:149:6:注意:'atoi'在这里声明为int atoi(const …