tags:

views:

117

answers:

3

Hi,

I'm coding a task monitoring, which updates tasks' progress using cout. I'd like to display one task progress per line, therefore I have to rollback several lines of the console.

I insist on "several" because '\b' does the job for one line, but does not erase '\n' between lines.

I tried std::cout.seekp(std::cout.tellp() - str.length()); but tellp() returns -1 (failure)...

Thanks in advance.

Regards,

Mister Mystère.

+7  A: 

Use an output formatting library such as ncurses if you can; this simplifies terminal manipulation significantly.

You
+3  A: 

Neither C nor C++ define anything like that. You need explicit terminal manipulation. On Unix you can use curses. Have no idea what's there for Windows.

Nikolai N Fetissov
+4  A: 

You can do cout << '\r'; to jump to the beginning of the current line, but moving upwards is system-specific. For Unix, see man termcap and man terminfo (and search for cursor_up). On ANSI-compatible terminals (such as most modern terminals available on Unix), this works to move up: cout << "\e[A";.

Don't try seeking in cout, it's unseekable most of the time (except when redirected to a file).

As mentioned in other answers, using the ncurses (or slang) library provides a good abstraction for terminal I/O on Unix.

pts
Thanks, I gave up monitoring several lines, and used \r - fill 79 spaces - \r instead.
Mister Mystère