[英]How to change the location of output or the cursor at output, for C++ in “Code Blocks”
Hi to enthusiasts programming, I use "Code Blocks" ver17.12 on windows10, now want to take the output result to row 10 and column 10, so i used gotoxy() function that the above IDE gave an error. 错误文本:'gotoxy' 未在此 scope 中声明。 需要注意的是,在主function之前,我把conio.h
然后我用谷歌搜索语法 gotoxy() 来更改 output 的 output 或 cursor 的位置,但我没有得到结果。 感谢您在这方面指导我。
您可以创建自己的gotoxy()
。 看一下这个程序结构:
#include <windows.h>
void gotoxy(int x, int y); // declaration
.
.
void gotoxy(int x, int y) {
static HANDLE h = NULL;
if (!h) h = GetStdHandle(STD_OUTPUT_HANDLE);
COORD c = {x, y};
SetConsoleCursorPosition(h, c);
}
或者,您可以输入:
#include <windows.h>
void gotoxy(int x, int y) {
COORD coord;
coord.X = x;
coord.Y = y;
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord);
}
笔记:
#include <windows.h>
必须为这两个代码所必需。conio.h
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.