I want to display a character at specific positions on screen using values like x and y. Is it possible?? i am not able to find the correct function. I tried to google but no luck.
I want to display a character at specific positions on screen using values like x and y. Is it possible?? i am not able to find the correct function. I tried to google but no luck.
-------------------------------------------------------------------
There are 10 kinds of people in this world....Those who understand binary and those who don't
You're looking for gotoxy().
-------------------------------------------------------------------
There are 10 kinds of people in this world....Those who understand binary and those who don't
ncurses is more portable than conio.
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
i have the same problem and ncurses(.h) is not found by c++Code:#include <iostream> #include <ncurses.h> using namespace std; int main() { gotoxy(3, 5); // what's the right command if the include file would work?? cout << "blah" << endl; cin.get(); }
ncurses is not standard header file. meaning, you have to link to it, which of course means you have to have it installed in your system first in order to work.
if portability is not of concern, then by all means, go with windows.h and use gotoxy, otherwise, install ncurses or pdcurses in your system, usually for usage in windows this means copying a dll to c:\windows\system32 and finding the appropriate linker command (should be in the documentation of the library).
the windows.h include file does not support gotoxy(). thats what VS C++ said...
portability - do you mean between operating systems? i mean - this IS portable to ALL other windows based computers when i use windows.h?
right portablility means between OS. including windows.h in a win32 app should work on any 2000/XP machine, and I would imagine it should work just fine with vista too (if it's a simple console app)
right, I think gotoxy like you said is in conio.h, another non-standard header. i do know there is a similar function in windows.h, although the name of this function eludes me right now, it's something like SetCursorPosition() or something of the sort.
Personally, I would find the windows.h function and use that if this program is for your benefit only.
you mean like this?this simply does not change the cursor position at all. it writes to position <1|1>.Code:#include <iostream> #include <windows.h> using namespace std; int main() { SetCursorPos(5, 10); cout << "blah" << endl; system("PAUSE"); }
this does neither work without 'endl' or with printf!
This is all I could find in my archives of old win32 console apps. I can't run this right now (have only Linux in front of me) but maybe this will work for you, maybe. Let me know how it goes...Code:#include <windows.h> int main(){ HANDLE console_handle; COORD cursor_coord; char *buffer = "X\n"; DWORD actual = 0; cursor_coord.X=(40-(strlen(buffer)/2)); cursor_coord.Y=10; console_handle = GetStdHandle(STD_OUTPUT_HANDLE); if(SetConsoleCursorPosition(console_handle, cursor_coord)){ WriteConsole(console_handle, buffer, strlen(buffer), &actual, NULL); } system("pause"); return 0; }
that writes a questionmark to the screen. also it would propably be good if you could write whole words at once, wouldnt it?
I just went to my Desktop, compiled exactly what I posted, and it worked. To write an actual word, just replace "x\n" with "word\n". I'm not sure why it printed a "?" to your screen.