Click here to Skip to main content
15,886,258 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Do you know of a simple way to move the cursor one line up by program on a console application (Command Prompt window) ?

In the old days, there were ANSI Escape sequences for this purpose, but they don't seem to be recognized.

The ASCII codes for Cursor up/Cursor down do not work either.

I have tried the Curses library, but couldn't find a way to access the already existing application console. And, frankly speaking, I'd prefer something simpler.

Cursor home and clear screen are also welcome, but I can do without them.
Posted
Updated 17-Oct-13 23:01pm
v3
Comments
Jochen Arndt 18-Oct-13 11:56am    
Have you tried SetConsoleCursorPosition()?
YvesDaoust 18-Oct-13 12:35pm    
Interesting. I think I once had a look at the Console API and couldn't find a way to get the handle to the application console.
YvesDaoust 18-Oct-13 12:40pm    
Hurray, by searching better, I found the GetStdHandle call which does the trick, and now it works !

Thanks alot. You can enter your comment as a solution, I'll validate it.
Jochen Arndt 19-Oct-13 4:12am    
Thank you for your feedback. I have added a solution.
YvesDaoust 19-Oct-13 6:13am    
I have been looking for such an easy solution for months (no daily :) ), and it was in front of my eyes !

You may use SetConsoleCursorPosition()[^]. Example code can be found at Using the High-Level Input and Output Functions[^].
 
Share this answer
 
Try to use ESC [ A, like this:

cout << "\x1b[A";

to move the cursor up one line.
 
Share this answer
 
Comments
YvesDaoust 18-Oct-13 11:00am    
This IS an ANSI escape sequence. They don't work in a Command Prompt window. Thanks for the attempt...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900