It's actually more complicated than that if you want to behave exactly like a compiler. What if the 'comments' are inside a double quote string literal ? You shouldn't skip that.
I guess he would have to play around and come up with all the different combinations first. There can't be that many and simple loops could account for them once all patterns are discovered.
At least now TS is pointed in the right direction.
What about using std::getline to read in an entire line to a std::string, then use the find and erase functions to ignore the comments?
1 2 3 4 5 6 7 8 9 10 11 12 13 14
std::string line;
std::getline(fileIn, line);
unsigned pos = line.find("//");
if (pos != std::string::npos)
line.erase(pos, std::string::npos); // erase to the end of the line
pos = line.find("/*");
if (pos != std::string::npos)
{
unsigned end = line.find("*/");
if (end != std::string::npos) end += 2; // size of "*/"
line.erase(pos, end - pos); // if it wasn't found, it will erase the whole line
}