Is there an "unput" for std :: ostream, for example, is there an "unget" for std :: istream?

I have parsing code that allows you to enter escape sequences in a line of text:

// In a file or large, multi-line string ...
my_parameter="A setting for the parameter\nthat contains \"escape sequence\" characters"

When I parse it, I process the backslash and add the corresponding character to the string that I create with the instance std::ostringstream. Line feeds, quotation marks, backslashes, etc. Everything is working fine. However, I pondered whether to allow the sequence \bor not, and looked to see if I could “deduce” the last character from mine ostringstream, how you could “disconnect” it from anyone std::istream. Can you do this? If the function does not exist, is there an easy way to move the recording position back one character and just write the next character to overwrite it?

This is not critical or something like that, but I was curious if anyone else had come across this before.

+3
source share
4 answers

Streams are terribly like mail. each message sent in a stream, like a letter, and messages can be queued in buffers that look like mailboxes.

If you are responsible for sending messages and sending messages from a mailbox, you probably know that the letter you just posted still exists so that you can return. Of course, you probably won't bother putting it in your inbox at all, since you have both ends.

If instead you send a letter to your friend’s mailbox, in fact you don’t have much control when she checks her mailbox and takes out all the letters. maybe she’s sitting at the door and will grab the letter directly and read it as soon as it passes through the slot.

, , ( ). - , . , , .

concurrency , . , , , .

+9

, , , . "allow getbacks":

int pending_ch = -1;
void output_char(int ch)
{
  if (pending_ch >= 0)
    putch(F, ch);
  pending_ch = ch;    
}
void unput_char(void)
{
  pending_ch = -1;
}
void force_put_char(void)
{
  output_char(-1);
}

, .

0

. Windows Console, . , .

0

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


All Articles