I need the characters/escape sequences that move the console's cursor position. It would be nice to know the left/right/up/down cursor controls, but if that's not possible, a home (go to the first character of the first line in the console). Thanks in advance.
+2
A:
There aren't any. The Windows console doesn't support such things. See this Wikipedia article for more info.
However, if you just need to return to the beginning of the line, you can just emit a carriage return - try this:
#include <iostream>
using namespace std;
int main() {
cout << "foo" << "\r";
cout << "bar" << "\n";
}
It should display "bar" with no "foo".
anon
2009-08-17 21:02:30
that's better than nothing, but is there any way to get back to the beginning of the console?
tiddlydum
2009-08-17 21:15:29
Not using control codes. You can of course write code that uses the console API, which allows you to output anywhere you like.
anon
2009-08-17 21:17:15
Yup. "\27[1;1H"
T.E.D.
2009-08-17 21:18:39
I was trying to avoid Conlib. Looks like I'll have to use it.
tiddlydum
2009-08-18 10:09:13
A:
C++ has no standard for cursor control on consoles. That's totally the OS's business.
However, most consoles, inculding XP's support the ANSI escape sequences.
If that isn't standard enough for you, you can try building curses on your system.
T.E.D.
2009-08-17 21:13:54
+1
A:
The best thing is to use the Console API. Here is the reference from MSDN. I think you wouldn't find the reference very helpful if you don't understand how the console works. The best tutorial I came to read is this one.
AraK
2009-08-17 21:14:26