c++ - Reading from ifstream won't read whitespace -
i'm implementing custom lexer in c++ , when attempting read in whitespace, ifstream won't read out. i'm reading character character using >>
, , whitespace gone. there way make ifstream keep whitespace , read out me? know when reading whole strings, read stop @ whitespace, hoping reading character character, avoid behaviour.
attempted: .get()
, recommended many answers, has same effect std::noskipws
, is, spaces now, not new-line character need lex constructs.
here's offending code (extended comments truncated)
while(input >> current) { always_next_struct val = always_next_struct(next); if (current == l' ' || current == l'\n' || current == l'\t' || current == l'\r') { continue; } if (current == l'/') { input >> current; if (current == l'/') { // explicitly empty while loop while(input.get(current) && current != l'\n'); continue; }
i'm breaking on while
line , looking @ every value of current
comes in, , \r
or \n
not among them- input skips next line in input file.
there manipulator disable whitespace skipping behavior:
stream >> std::noskipws;
Comments
Post a Comment