0

How can I rewind std::cout back to beginning of line and insert text without overwriting exiting one ? Can it be done using just standard c++ functions, or do I need low-level OS functions for console to do this ?

EDIT: I'm writing a simple telnet client. So when a message is received it should be appended at the top and user imput should not be overwritten.

Matej Gomboc
  • 161
  • 3
  • 10
  • Maybe this will help: https://stackoverflow.com/questions/3057977/rewinding-stdcout-to-go-back-to-the-beginning-of-a-line#3057994 – informant09 Apr 01 '18 at 14:36
  • Can you please elaborate what you want to do, and what you have tried to do to solve your problem? Can you give some examples of the expected output in different situations? Please [read about how to ask good questions](http://stackoverflow.com/help/how-to-ask), and learn how to create a [Minimal, Complete, and Verifiable Example](http://stackoverflow.com/help/mcve). – Some programmer dude Apr 01 '18 at 14:45

2 Answers2

0

No, you can't do this, and it's considered useless in console. There is a function named std::seekp for all basic_ostream based class. But when you apply this to cout, no effect at all but failbit is set.

con ko
  • 1,368
  • 5
  • 18
0

Use std::cout << '\xd' this line will output a carriage return which will fulfill your requirement. This this line will overlap your previous entry.

Abhijit Pritam Dutta
  • 5,521
  • 2
  • 11
  • 17