这更像你想要的吗?
#include#include #include #include #include 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 (isspace)))); if(line[0] == '#') continue; int data; stringstream(line) >> data; cout << "Data: " << data << endl; } return 0; }