如何在C++中跳过读取文件中的行?

nev*_*int 4 c++ file-io

该文件包含以下数据:

#10000000    AAA 22.145  21.676  21.588
10  TTT 22.145  21.676  21.588
1  ACC 22.145  21.676  21.588
Run Code Online (Sandbox Code Playgroud)

我尝试使用以下代码跳过以"#"开头的行:

#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;
   }
}
Run Code Online (Sandbox Code Playgroud)

但由于某种原因,它给出了这个错误:

Mycode.cc:13:错误:请求'tableEntry'中的成员'find',这是非类型'int'

CTT*_*CTT 9

这更像你想要的吗?

#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <algorithm>

using namespace std;

int main() 
{
    fstream fin("myfile.txt");
    string line;
    while(getline(fin, line)) 
    {
        //the following line trims white space from the beginning of the string
        line.erase(line.begin(), find_if(line.begin(), line.end(), not1(ptr_fun<int, int>(isspace)))); 

        if(line[0] == '#') continue;

        int data;
        stringstream(line) >> data;

        cout << "Data: " << data  << endl;
    }
    return 0;
}
Run Code Online (Sandbox Code Playgroud)