Archived

This topic is now archived and is closed to further replies.

AaronShlock

Basic C++ 'cout' question

Recommended Posts

How do you move the virtual cursor? For instance, say I had this line: cout<<"__________"; And then... cin>>x; But I want to have the cin OVERWRITE the cout... as in backing up the virtual cursor ten spaces so that whatever is typed will replace the characters below it...

Share this post


Link to post
Share on other sites
You can''t do it with cout. You need platform-specific console I/O. Under Win32, you''ll need to look into GetStdHandle(), SetConsoleCursorPosition(), ConsoleWriteOutput(), ConsoleWriteChar() and so on.

I wanna work for Microsoft!
[ GDNet Start Here | GDNet Search Tool | GDNet FAQ | MS RTFM [MSDN] | SGI STL Docs | Google! ]
Thanks to Kylotan for the idea!

Share this post


Link to post
Share on other sites
try this:

    

#include <windows.h>
#include <iostream>
usuing namespace std;

int main()
{

HANDLE H_OUTPUT = GetStdHandle(STD_OUTPUT_HANDLE);
COORD cursor = {0,0};

cout << "________";
SetConsoleCursorPosition(H_OUTPUT, cursor);
cin >> x;

return 0;

}



Try that I didn't test it but I think it will work.

COORD cursor is the place where you want it to go. Play around with the values and see what happens.

Jeff D


Suffered seven plagues, but refused to let the slaves go free. ~ Ross Atherton


Edited by - Jeff D on February 17, 2002 2:36:56 AM

Share this post


Link to post
Share on other sites