我现在想弄清楚为什么它坏了,因为我让它工作了,但我不确定哪里出了问题。我正在尝试从一个已打开的文件中获取一个简单的 getline,但是,编译器一直给我错误。我试过找其他有这些问题的人,但我没能找到其他人。有什么建议吗?
void Foo::bar(ifstream &inputFile)
{
// Read in the data, parse it out, and
// call loadQueue
string input;
do {
getline(inputFile, input);
loadQueue(input);
}while (!(inputFile.eof()));
}
这是我得到的返回:
g++ -c -o Airworthy.o Airworthy.cpp
Foo.cpp: In member function ‘void Airworthy::readData(std::ifstream&)’:
Foo.cpp:25:27: error: no matching function for call to ‘getline(std::ifstream&, std::string&)’
Foo.cpp:25:27: note: candidates are:
In file included from /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.2/../../../../include/c++/4.7.2/string:55:0,
from /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.2/../../../../include/c++/4.7.2/bits/locale_classes.h:42,
from /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.2/../../../../include/c++/4.7.2/bits/ios_base.h:43,
from /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.2/../../../../include/c++/4.7.2/ios:43,
from /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.2/../../../../include/c++/4.7.2/ostream:40,
from /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.2/../../../../include/c++/4.7.2/iostream:40,
关于这个问题有什么想法吗?
最佳答案
很可能您忘记了#include
所有必需的标准 header 。一种可能是:
#include <fstream>
或者您可能忘记了:
#include <string>
您始终必须明确地#include
所有相关的标准 header ,而不依赖于通过其他一些 header 的间接包含。
关于c++ - 打开文件流输入的 Getline 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16264205/