answersLogoWhite

0


Best Answer

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);

}

User Avatar

Wiki User

9y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

10y ago

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.

This answer is:
User Avatar

User Avatar

Wiki User

11y ago

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++.

This answer is:
User Avatar

User Avatar

Wiki User

14y ago

#include

...

gotoxy (1,1);
cprintf ("Top-left corner");

This answer is:
User Avatar

User Avatar

Wiki User

13y ago

Puts the cursor into the given position. (For more information use the built-in help.)

This answer is:
User Avatar

User Avatar

Wiki User

11y ago

Use the built-in help. (Press F1)

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Can we use gotoxy function in C plus plus?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

Why to use gotoxy function in c plus plus?

to locate coordinates ..


Tell more about gotoxy statemant and more of its use in c and c plus plus?

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.


How do you write a program using the gotoxy statement and print function to display letters of the alphabet on the computer screen?

There is no gotoxy statement in C.


What is the header file for gotoxy 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 &lt;stdio.h&gt; #include &lt;conio.h&gt; #include &lt;windows.h&gt; // 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 }


What is syntax in gotoxy?

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;}

Related questions

Why to use gotoxy function in c plus plus?

to locate coordinates ..


Which header file is used for gotoxy function in turbo c plus plus?

It's in conio.h, but don't use gotoxy. Use SetCursorPosition() instead.


Tell more about gotoxy statemant and more of its use in c and c plus plus?

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.


What is gotoxy in turbo c?

A function, defined in conio.h. Use the help.


How do you write a program using the gotoxy statement and print function to display letters of the alphabet on the computer screen?

There is no gotoxy statement in C.


What is the header file for gotoxy 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 &lt;stdio.h&gt; #include &lt;conio.h&gt; #include &lt;windows.h&gt; // 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 }


What is syntax in gotoxy?

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;}


What is the meaning of gotoxy?

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.


How do you create folder with c plus plus?

Use function mkdir.


How do you enter a sentence as input in c plus plus?

Use the C++ getline() function from the standard library.


How do you set the cursor in turbo c?

gotoXY from conio.h


What is the operator of power in c plus plus?

There is no "power" operator in C or C++. You need to the use the math library function pow().