what library do i need to use a function like setxy(x,y) to align my text, or are there any other funcions to do that out there as well?
Printable View
what library do i need to use a function like setxy(x,y) to align my text, or are there any other funcions to do that out there as well?
This is implementation dependent, what compiler/OS do you use?
-Prelude
i use dev c++ 4.9.7 mingw 3.2 i beleive, and thanks for always helping prelude :D
I believe Dev C++ supports the Win32 API. If so then this should work nicely.
-PreludeCode:#include <windows.h>
void gotoxy (int x, int y )
{
COORD coord;
coord.X = x;
coord.Y = y;
SetConsoleCursorPosition ( GetStdHandle ( STD_OUTPUT_HANDLE ), coord );
}
hm.. it says coord is undefined, any ideas or something i should have also done?
>any ideas or something i should have also done?
If you pasted the code exactly as I posted then it should work. There is another thing you can try though, if I remember correctly, your compiler does implement gotoxy in conio.h or conio.c. Try including one of them and see if you can use it. be sure to remove the function I gave you though. :)
-Prelude
I tried the code, written by Prelude, and it worked fine using Dev C++ 4.
can't u just use setw() from iomanip.h?
if you do setw(), then you have to do a number of things to center.
Code:
#include <cstring.h>
#include <iostream.h>
#include <iomanip.h>
main()
{
string name = "TITLE";
int length;
length = strlen(name.c_str())/2;
cout << setiosflags(ios::right);
cout << setw(40-length) << name << endl;
}