views:

365

answers:

3

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
that's better than nothing, but is there any way to get back to the beginning of the console?
tiddlydum
Not using control codes. You can of course write code that uses the console API, which allows you to output anywhere you like.
anon
Yup. "\27[1;1H"
T.E.D.
I was trying to avoid Conlib. Looks like I'll have to use it.
tiddlydum
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.
XP doesn't support ANSI escape sequences.
anon
+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