Ideally you would not manipulate std::cout using such a low-level function. Console output is intentionally generic so that output can be easily redirected to any output device that accepts a character stream. As such, this code will not work correctly if the user were to redirect output to a disk file or a printer, or use the output as input to another program. If you wish to format screen output in a non-generic manner, do not use the console, use a screen-specific context device instead.
#include<iostream>
#include<string>
#ifdef WIN32
#include<windows.h>
#endif WIN32
void gotoxy(int x, int y)
{
#ifdef WIN32
static HANDLE h = NULL;
if(!h)
h = GetStdHandle (STD_OUTPUT_HANDLE);
COORD c = { x, y };
SetConsoleCursorPosition (h,c);
#elif linux
printf("%c[%d;%df",0x1B,y,x);
#else
static_assert (false, "unsupported platform in gotoxy()");
#endif WIN32
}
void draw_box(unsigned x, unsigned y, unsigned width, unsigned height)
{
gotoxy (x, y);
std::cout << std::string (width, '*');
for (unsigned z=2; z<height; ++z)
{
gotoxy (x, ++y);
std::cout << "*";
gotoxy (x+width-1, y);
std::cout << "*";
}
gotoxy (x,++y);
std::cout << std::string (width, '*');
}
int main()
{
draw_box(10,10,5,4); // draw 5x4 box at {10,10}
gotoxy (0,25);
}
gotoxy() is not part of the standard library and any implementation you encounter is unlikely to be cross-platform compatible. If cross-platform isn't a concern then use OS-specific calls such as SetConsoleCursorPosition() in Windows and putp() in UNIX (don't forget to install ncurses). You can also "roll-your-own" version of gotoxy() as a function that caters for all the platforms that you intend to target, but you must distribute the function along with any code that uses it if you intend to share your code.
gotoxy() function is defines in conio.h library. However this header file is not defined in GCC standards and hence an attempt to include the file will produce error message if the compiler is based on GCC standards. However, you can use it in Turbo C++.
#include
...
gotoxy (1,1);
cprintf ("Top-left corner");
Puts the cursor into the given position. (For more information use the built-in help.)
Use the built-in help. (Press F1)
to locate coordinates ..
gotoXY function is defined in conio.h, it places the cursor to the given position. If you have any question about it, use the built-in help.
There is no gotoxy statement in C.
There is no such function as gotoxy(). It was originally a standard function in conio.h, used to set the console cursor position, but it was deprecated because it was non-portable. While it may still exist in older C compilers, its usage would be frowned upon today and no known C or C++ compiler should support such a function these days. You are free to "roll your own" version of the function, of course. The following version works on Windows only. But given how little it actually adds to what already exists, and its non-portable nature it hardly seems worthwhile. #include <stdio.h> #include <conio.h> #include <windows.h> // Standard version: void gotoxy( COORD c ) { SetConsoleCursorPosition( GetStdHandle( STD_OUTPUT_HANDLE ), c ); } // Overloaded version emulating original gotoxy function: void gotoxy( int x, int y ) {COORD c;c.X = x;c.Y = y; gotoxy( c ); // call standard version }
AnswerGotoXY is a function or procedure that positions the cursor at (X,Y), X in horizontal, Y in vertical direction relative to the origin of the current window. The origin is located at (1,1), the upper-left corner of the window. AnswerDescription This shows how to use the gotoxy function in C to move the text cursor to a different location on the screen Code#include#includeint main(void){int i;printf("This is the first line.\n");gotoxy(10,4);printf("This is the second line.\n");gotoxy(20,8);printf("And this is line 3.\n");return 0;}
to locate coordinates ..
It's in conio.h, but don't use gotoxy. Use SetCursorPosition() instead.
gotoXY function is defined in conio.h, it places the cursor to the given position. If you have any question about it, use the built-in help.
A function, defined in conio.h. Use the help.
There is no gotoxy statement in C.
There is no such function as gotoxy(). It was originally a standard function in conio.h, used to set the console cursor position, but it was deprecated because it was non-portable. While it may still exist in older C compilers, its usage would be frowned upon today and no known C or C++ compiler should support such a function these days. You are free to "roll your own" version of the function, of course. The following version works on Windows only. But given how little it actually adds to what already exists, and its non-portable nature it hardly seems worthwhile. #include <stdio.h> #include <conio.h> #include <windows.h> // Standard version: void gotoxy( COORD c ) { SetConsoleCursorPosition( GetStdHandle( STD_OUTPUT_HANDLE ), c ); } // Overloaded version emulating original gotoxy function: void gotoxy( int x, int y ) {COORD c;c.X = x;c.Y = y; gotoxy( c ); // call standard version }
AnswerGotoXY is a function or procedure that positions the cursor at (X,Y), X in horizontal, Y in vertical direction relative to the origin of the current window. The origin is located at (1,1), the upper-left corner of the window. AnswerDescription This shows how to use the gotoxy function in C to move the text cursor to a different location on the screen Code#include#includeint main(void){int i;printf("This is the first line.\n");gotoxy(10,4);printf("This is the second line.\n");gotoxy(20,8);printf("And this is line 3.\n");return 0;}
gotoxy is a function in some programming languages, such as Turbo C, that is used to move the cursor position to a specific coordinate on the screen. This function is commonly used in text-based console applications to control where text or graphics are displayed.
Use function mkdir.
Use the C++ getline() function from the standard library.
gotoXY from conio.h
There is no "power" operator in C or C++. You need to the use the math library function pow().