how to read and parse text files with istringstream?
问题 I am trying to read a .txt file line by line: vector<vector<int>> iVecGrid; vector<int> iVecRow; ifstream text; text.open("grid.txt", ios::in); if (!text) { cout << "Error!\n"; return EXIT_FAILURE; } istringstream isLine; string sLine; while (getline(text, sLine)) { isLine.str(sLine); int iNumber; while (isLine >> iNumber) { cout << iNumber << " "; iVecRow.push_back(iNumber); } cout << endl; iVecGrid.push_back(iVecRow); iVecRow.clear(); } When I put isLine inside the while (getline(text,