468,463 Members | 1,988 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,463 developers. It's quick & easy.

beginner: console cursor movement

1) is there another way to move the cursor besides the escape sequences in win32 console applications?

2) i want to move my cursor up, or to be precise - backward. example:

my code generates this on the screen (\n meaning new line):
\n
HEY, DONT ERASE ME.
\n
and my erase() function sould erase all cappital Es and replace them with a *.
all i need to know is how to get up and backward without erasing anything.

IMPORTANT : the original is not to be reprinted on the screen, everything is to remain, with only the Es substituted.

i.e. cout <<"\b" is backspace, that erases

and i tried "\v", vertical tab, but i got smth. strange.

Please help.
Feb 3 '08 #1
7 16149
weaknessforcats
9,207 Expert Mod 8TB
The stdout console is a replacement for a console typewriter that was standard equipment on computers in the 1970's when C was invented.

So, all you can do is type a line and go to the next line ort maybe go back to the start of the current line. There is no gotoxy() like in Unix.

You would have to clear the screen and re-display it.

Other than that, you need to write an actual Windows application where you do have freedom to move around as you wish.
Feb 3 '08 #2
oler1s
671 Expert 512MB
As the console is OS specific, you would have to look up the Win32 API ( http://msdn2.microsoft.com/en-us/library/ms682087.aspx ).
Feb 3 '08 #3

You would have to clear the screen and re-display it.

Other than that, you need to write an actual Windows application where you do have freedom to move around as you wish.
thank you for the advice. i have some more questions:

1) the program is an exercise im working on from a book, and it needs to be written like a console program (win32 or whatever), no MFC or Visual Studio Forms (not yet at least :)
2) i'm working on Linux OpenSUSE and i'm making my code with g++ compiler. my question: how to clear the screen? My program displays graphical objects (objects are from a derived class) by calling virtual display functions, on the screen. so, i'm supposed to plot a square on the screen, and make it appear to move by rewriting the screen again, thus deleting the square, and rewriting the square on the screen, only in a different place. i can do that, but i still don't know how, because whatever i do std::cout will continue where it stopped last. how to clear the screen and make the cursor go to the beginning? and here's another problem: the Linux shell prompt is displays every time the program ends.

sorry for the HUGE post, and thank You for your time and patience.
Feb 3 '08 #4
i forgot to mention that my "graphic" objects are not graphic by nature, i defined myown classes for them
they look like

*********
*********
*********
*********
*********

for example. I'm supposed to make that move. I know how to do it, all i need to know is how to "climb up", because the exercise states that i have to write a virtual class method that searches for a ' * ' and replaces it with ' ': so clearing the screen is not an option? objects are written using simple loops and cout <<' * '. instance data for the base class are X and Y coordinates on the console and the "graphic" object dimension. objects are diversed by their draw() function.
Feb 3 '08 #5
weaknessforcats
9,207 Expert Mod 8TB
so clearing the screen is not an option?
I don't know why you can't do that.

I mean Windows updates by a clear and repaint. There you identify a rectangle and mark it invalid. That will tigger a call to your paint function.

It's how movies work.
Feb 4 '08 #6
bfoo75
12
I did a project like this in highschool.... although I don't know how to read in a character thats already on the screen.... If I remember right it was just a matter of finding the right library to use. I wanna say Conio.h, but I havn't programmed in C++ using console graphics for about 5 years. The function you would use is a gotoxy(x,y) and it just rewrites over whatever you output after that. I wish I had my old assignments so I could tell you forsure, but they are long gone.

Another thing to look out for is that I found some of the old C++ libraries differed from a '94 version of a borland compiler and microsofts visual studios. I'll do some research and find out if I can get you an answer.
Feb 4 '08 #7
bfoo75
12
iomanip.h was the library I was thinking of, although conio.h also looks like it has functions to read from the console stream.

If you go search iomanip.h +gotoxy in google, you get a buncha posts about problems with compiling and stuff about Turbo C++ 3.0 and graphic libraries. That might have been what I was thinking with the differences in libraries, so you might have to track them down. Hope that helps.
Feb 4 '08 #8

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

2 posts views Thread by Robin Shuff | last post: by
10 posts views Thread by Danny | last post: by
5 posts views Thread by Amar Prakash Tripaithi | last post: by
10 posts views Thread by R.A.M. | last post: by
4 posts views Thread by RedDevil | last post: by
reply views Thread by kmladenovski | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.