Ignore check () for values

When you use ignore () in C ++, is there a way to check those values ​​that were ignored? I mostly read a few characters and want to know if I ignored the usual characters in the text, or if I first got a newline character. Thank.

+3
source share
3 answers

I don’t believe that - you have to "roll your own."

In other words, I think you will have to write code that is read from the stream using get()and then add some logic to save what you need and ignore the rest (while you check that you are not paying attention).

+1
source

, ignore() . get() , , .

+1

delim ignore(), :

streampos old = is.tellg();
is.ignore(num, '\n');
if (is.tellg() != old + num) {
    // didn't ignore "num" characters, if not eof or error then we
    // must have reached a newline character.
}

, , ignore() , . , , tellg() old + num. AFAIK , . , .

I also don’t know if and when it will be more than just reading numbytes and looking for it for newlines. My initial thought was: "what part of the difference between ignore()and is read()not obvious?"; -)

0
source

Source: https://habr.com/ru/post/1735675/


All Articles