my code is like this:
int line_number = 0; while (getline(infile, line)) { stringstream lineStream(line); line_number++; string token; while (lineStream >> token); } If some tokens are not what I expect, then I will output a syntax error with line number and character offset. But the question is how I'm able to get character offset, is there any simple way I can get tokens' first letter's position?
tellg()to look at the updated position in thestringstream()after extracting a token, then subtracting the token's length. That feels iffy. In this kind of a situation, I would just parse eachlinemanually, instead of usingstringstream, and get down to the nitty-gritty details myself.tellg()is only useful for binary files... Also, your question has an answer here.