can any function, for example printf, restart from beginning of the same line? So we will not have multiple lines of output
Another question, any way to retrieve the previous ouput that have been bumped out of the window in case of large amount of output? I am using Windows VC.
Thanks!

By clearing the screen, on most Windows systems system("cls"); . Not compatible with a lot of other OSes though.
So a loop with newlines might be enough to push the rest out of view.

The second question; just record everything to an array of stucts(with output, input, ect.), similar to an undo buffer.

Think: a console program does not know what device receives stdout/cout output! Suppose you have prog.exe. See what happens when prog.exe started:
1. >prog -- ok, printf prints in console window
2. >prog >output.txt -- printf writes in file output.txt
3. >prog >nul -- printf "prints" nowhere (nul device - output is suppressed)
4. >prog <answers.txt -- print in window but read from the file answers.txt
...and so on...
You can't distinguish four cases above in your program.
So stdout/cout are treated as a classical one-way portal ;)

If you want full control over console input/output use implementation-dependent libraries. No such entity as console in standard stream i/o in C and C++.

printf("\r");

It may be compiler-specific, it may be platform dependent, so use discretion but give it a try.

The printf("\r") works really well to have the console screen overwrite the 'current' line. It will however just be another character in the output if cout is redirected to a file.

I used to use that feature to show progress for an old command line compiler, it would output the current source line number and then use '\r' to 'go back' and overwrite it with the next line number.

When the line numbers weren't important, I've also used it to make a 'spinner' using the character - \ | / in rotation. (If used sequentially, it looks like the line is 'spinning' in place.) So the user could see that the program was really still doing something.

And its been a while, but I vaguely remember that there were O/S dependent ways to detect if cout was to the console or a file. (It's always better if you don't care, but features like the "I'm still alive spinner" make no sense in the file.)

clreol : clears all characters from the current position to the end of line within the current text window,without moving the cursor.
delline:deletes the line containing the cursor and moves all lines below it one line up.
it depends on the compiler you use..

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.