I am using the gotoxy function and I have a question:
Is it possible to get the current x and y coordinates of your program f.e first gotoxy to lets say 5,6 and then return to the spot the cursor came from
I am using the gotoxy function and I have a question:
Is it possible to get the current x and y coordinates of your program f.e first gotoxy to lets say 5,6 and then return to the spot the cursor came from
If you have access to Win32 APIs, GetConsoleScreenBufferInfo can help you.
I don't think there is a portable way to get console cursor position anyway... Anyone else?
Merc
Well i came this far but it returns only crap, because I dont know how to use GetConsoleScreenBufferInfo properly I just guessed somewhat
Code:CONSOLE_SCREEN_BUFFER_INFO csbi; PCONSOLE_SCREEN_BUFFER_INFO pcsbi=&csbi; HANDLE h; GetConsoleScreenBufferInfo(h,pcsbi); cout<<csbi.dwCursorPosition.X<<","<<csbi.dwCursorPosition.Y;
You must be having functions if it is console..
wherey() and wherex() this is found in the header conio.h but remember this is not standard.. so you have a chance that this is not present in your compiler...
no I couldnt find t in my compiler......
somebody else has an solution?
Over here: http://faq.cprogramming.com/cgi-bin/...&id=1043284392Code:#include <windows.h> void gotoxy(int x, int y) { COORD coord; coord.X = x; coord.Y = y; SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord); }
Last edited by knave; 04-25-2003 at 07:33 AM.
where are these good for?Code:void t1 ( void ) { CONSOLE_SCREEN_BUFFER_INFO csbi; HANDLE h = GetStdHandle(STD_OUTPUT_HANDLE); COORD pos = { 10, 12 }; SetConsoleCursorPosition( h, pos ); WriteConsole( h, "hello\nworld", 11, NULL, NULL ); // does NOT change cursor position // cout << "foo"; GetConsoleScreenBufferInfo(h,&csbi); cout<<csbi.dwCursorPosition.X<<","<<csbi.dwCursorPosition.Y<<endl;}
and if I try this:
I want it to have it display: "3,5" wich it doesntCode:CONSOLE_SCREEN_BUFFER_INFO csbi; HANDLE h = GetStdHandle(STD_OUTPUT_HANDLE); //cout<<"foo"; cout<<"\n\n\n"<<"12345"; GetConsoleScreenBufferInfo(h,&csbi); cout<<csbi.dwCursorPosition.X<<","<<csbi.dwCursorPosition.Y<<endl;
It seems display only the Y-value if I use endl
Is there a way to have -cout<<"foo"- change the cursor position
so that other "cout's" change the cursor position as well
Last edited by Ivan!; 04-25-2003 at 10:00 AM.
As I dont know where cout.flush() is good for, I dont know why it works, but who cares: it works
Thanks!
It flushes everything out of the stream. Basically, if anything is in the stream, it is immediately written to the proper location upon the calling of flush.