gpt4 book ai didi

c++ - gotoXY 显示在屏幕上

转载 作者:行者123 更新时间:2023-11-30 04:48:33 26 4
gpt4 key购买 nike

我知道我的问题很愚蠢,但我仍然需要你的帮助。为什么 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)";
}

它是这样显示的:

___________________________________________________________________________________________________________________________
| | 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

不是,它实际上显示在第 5 行。

我平台上的默认控制台宽度是 120 像素。当打印的行太长而无法适应 120 像素的限制时,Windows 控制台将自动创建一个新行,因此 Y=Y+1。

这段代码很可能适合你,因为宽度较短......

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

您可以将控制台宽度调整到更宽的长度,它应该会按预期工作。

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

关于c++ - gotoXY 显示在屏幕上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55770540/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com