該文件包含以下數據:如何跳過用C++讀取文件中的一行?
#10000000 AAA 22.145 21.676 21.588
10 TTT 22.145 21.676 21.588
1 ACC 22.145 21.676 21.588
我試圖跳過開始以「#」線路使用下面的代碼:
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
using namespace std;
int main() {
while(getline("myfile.txt", qlline)) {
stringstream sq(qlline);
int tableEntry;
sq >> tableEntry;
if (tableEntry.find("#") != tableEntry.npos) {
continue;
}
int data = tableEntry;
}
}
但由於某些原因,給出了這樣的錯誤:
Mycode.cc:13: error: request for member 'find' in 'tableEntry', which is of non-class type 'int'
+1爲編譯器。你不明白哪部分錯誤? – xtofl 2009-02-23 10:26:40
xtofl:老兄,如果我可以+1的評論,笑我的屁股:) – 2009-02-24 17:28:32