我想弄清楚爲什麼這是現在破產,因爲我有它的工作,我不知道什麼是錯的。我正在嘗試從已打開的文件中獲取簡單的getline,但是,編譯器不斷給我提供錯誤。我試圖找到其他人有這些問題,但我一直無法找到任何其他人。有什麼建議?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,
在這個問題上是什麼任何想法?
除了Andy所說的,你可能會爲文件的最後一行調用兩次loadQueue。改變你的循環爲'while(getline(inputFile,input)){loadQueue(input); }'。 – 2013-04-28 15:13:12
請向我們展示整個錯誤消息。爲了詳細闡述sftrabbit,當沒有更多輸入時,'eof()'不會返回true,它只會在輸入操作由於eof而失敗後返回true。 – Potatoswatter 2013-04-28 15:50:45
@Patatoswatter否。問題是_until_輸入失敗,'eof()'可能會或可能不會返回'true'。讀完最後一行(或最後一個輸入,不管它是什麼)後,'eof()'可以返回'true'或'false';你不能確定哪一個。 – 2013-04-28 16:06:35