这是有错误的代码部分:
std::vector<int> loadNumbersFromFile(std::string name)
{
std::vector<int> numbers;
std::ifstream file;
file.open(name); // the error is here
if(!file) {
std::cout << "\nError\n\n";
exit(EXIT_FAILURE);
}
int current;
while(file >> current) {
numbers.push_back(current);
file.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
}
return numbers;
}
好吧,我有点不知道发生了什么。整个事情在VS中正确编译。但是我需要用 dev cpp 编译它。
我在上面的代码中注释掉了抛出错误的行。错误是:
no matching function for call 'std::basic_ifstream<char>::open(std::string&)
no matching function for call 'std::basic_ofstream<char>::open(std::string&)
在代码的不同部分,我得到了类似numeric_limits is not a member of std
, 或的错误max() has not been declared
,尽管它们存在于iostream
类中并且一切都在 VS 中工作。
为什么我会收到此错误?