简体   繁体   中英

gotoXY display on the screen

I know my question is silly but I still need your help.why function of gotoxy do not work expect?

void gotoxy(int x,int y)
{
    COORD coord={x,y};
    SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),coord);
}
using namespace std;
int main()
{
    cout<<"___________________________________________________________________________________________________________________________\n";
   cout<<"|                |      XUAT SAC      |        GIOI        |        KHA         |     TRUNG BINH     |        YEU         |\n";
   cout<<"|     MA LOP     |--------------------------------------------------------------------------------------------------------|\n";
   cout<<"|                |    SL    |    %    |    SL    |    %    |    SL    |    %    |    SL    |    %    |    SL    |    %    |\n";
   cout<<"|-------------------------------------------------------------------------------------------------------------------------|\n";
   gotoxy(0,5);cout<<"gotoxy(0,5)";
}

and it is display this:

___________________________________________________________________________________________________________________________
   |                |      XUAT SAC      |        GIOI        |        KHA         |     TRUNG BINH     |        YEU         |
   |     MA LOP     |--------------------------------------------------------------------------------------------------gotoxy(0,5)

I want to gotoxy(0,5)on the screen but it is display in the line of 3

I want to gotoxy(0,5)on the screen but it is display in the line of 3

No, it's actually displayed on line 5.

Default console width on my platform is 120 pixels. When the line printed is too long to fit into the 120 pixels restriction windows console will automatically create a new line, hence Y=Y+1.

This code will most likely work for you since the width is shorter...

std::cout << "_____________________1\n";
std::cout << "_____________________2\n";
std::cout << "_____________________3\n";
std::cout << "_____________________4\n";
std::cout << "_____________________5\n";


gotoxy(0, 5); 
cout << "gotoxy(0,5)";

You can adjust the console width to a wider length and it should work as expected.

https://www.howtogeek.com/howto/19982/how-to-make-the-windows-command-prompt-wider/

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