[英]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?我知道我的问题很愚蠢,但我仍然需要您的帮助。为什么 gotoxy 的功能不起作用?
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我想在屏幕上显示 gotoxy(0,5) 但它显示在第 3 行
No, it's actually displayed on line 5.不,它实际上显示在第 5 行。
Default console width on my platform is 120 pixels.我平台上的默认控制台宽度是 120 像素。 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.当打印的行太长而无法放入 120 像素限制窗口时,控制台会自动创建一个新行,因此 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/ https://www.howtogeek.com/howto/19982/how-to-make-the-windows-command-prompt-wider/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.