我知道我的问题很愚蠢,但是我仍然需要您的帮助。为什么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
答案 0 :(得分:1)
我想在屏幕上显示oxy(0,5),但显示在第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/