How do I set cursor position to beginning of line in C++?
c++, linux
Solution
That's what the carriage return character is for: `\r`. It is named after the mechanism of typewriters that returns the paper carriage to the right so that the typist can continue typing from the beginning of a line. Try this:
std::cout << "10 seconds have passed";
std::cout << "\r11";
Of course, with no delay between the two (except perhaps waiting on I/O), you're unlikely to see the change, but you will at least see the output as `11 seconds have passed` with `10` nowhere to be seen.
How to display the carriage return is entirely up to whatever you're outputting to, but this is its intention. For more complex cross-platform terminal output, take a look at ncurses.
Problem
So I'm trying to make part of a code where it writes something, then overwrites it. Like this: ``` 10 seconds have passed 11 seconds have passed 12 seconds have passed ``` without using a new line to print it. So I don't want to use something like this: ``` std::cout<<"10 seconds have passed\n" std::cout<<"11 seconds have passed\n" ``` How do I do this? I'm running Kubuntu Linux