I'm trying to figure out why this is broke now, because I had it working and I'm not sure what is wrong. I'm trying a simple getline from a file that's been opened, however, the compiler keeps giving me errors. I've tried finding someone else with these issues, but I haven't been able to find anyone else with this. Any advice?
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()));
}
Here is what I get in return:
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,
Any ideas on what the issue is?
loadQueue
being called for the last line of your file twice. Change your loop towhile (getline(inputFile, input)) { loadQueue(input); }
. – Tremanneof()
doesn't return true when there's no more input, it only returns true after an input operation has already failed due to eof. – Franchoteof()
may or may not returntrue
. After having read the last line (or the last input, whatever it is),eof()
may return eithertrue
orfalse
; you can't really be sure which. – Messer