Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 238
  • Last Modified:

Writing to standard output in C++

I want to write to the standard output, but I want to be able to write to the same area more than once.
So if I have a cout<<"message1", and I have more than 1 message, I want to be able to cout<<"message #" in the same spot in the console that message1 was outputted to the screen.  I think I have to decrement the stream pointer to the stdout, but I'm not sure how to do it.  Is it even possible?
Thank you,
K
0
KayodeCS_BU
Asked:
KayodeCS_BU
1 Solution
 
ExceterCommented:
0
 
KocilCommented:
The easiest way is :
  cout<<"message 1\r";
  cout<<"message #\r";

If you use Borland compiler, you have more options by using <conio.h> and use something like

  gotoxy(1,1);
  clreol();
  cprintf("message 1");

 
0
 
KayodeCS_BUAuthor Commented:
Ok, it didn't work at first, but I flushed the stdout buffer,cout<<flush;, between the two messages and I got it to work.  Thank you, I've never seen the \r before.
K
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now