简体   繁体   中英

How to use function gotoxy(int x, int y)

I included cstdlib, stdlib.h, stdio.h, conio.h, iostream, and then I typed using namespace std...(bla bla bla bla), and gotoxy()...But then the red curly underline and build(loading...) and... "build failed"... Then okay, I tried many times and nothing.Can anybody (please!!) tell me what`s wrong with the code? Here it is:

#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <cstdlib>
#include <conio.h>
using namespace std;
int main()
{
    gotoxy(20, 30);
}

I consider that THIS function is not supposed to be declared before use

By the way thank you in advance cause I`m desperate

For VC++ you can use SetConsoleCursorPosition() to define you own function, since gotoxy() function is not available in the standard libraries:

#include <windows.h>    
void gotoxy(int x, int y)
{
    COORD coordinate;
    coordinate.X = x;
    coordinate.Y = y;
    SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coordinate);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM