如何更改输出的位置或光标在输出处,以便在"Code Blocks"中C++
How to change the location of output or the cursor at output, for C++ in "Code Blocks"
嗨,编程爱好者,我在 windows17.12 上使用"代码块"ver10,现在想将输出结果带到第 10 行和第 10 列,所以我使用了上面的 IDE 给出错误的 gotoxy(( 函数。错误文本:"gotoxy"未在此范围内声明。 需要注意的是,在主函数之前,我把conio.h
然后我在谷歌上搜索语法gotoxy((来更改输出的位置或输出上的光标,但我没有得到结果。 感谢您在这方面指导我。
您可以创建自己的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>
必需的。 - GCC 编译器不支持
conio.h
。 - 您无需删除任何头文件。
相关文章:
- 递归函数计算序列中的平方和(并输出过程)
- 如何使用 < 和 > 命令获取 c++ 中的输入和输出?
- 请解释"函数1(p1,p2,p3);"的输出
- C++:将控制台输出存储在宏中更好吗
- 创建一个函数以在输入为负数或零时输出字符串.第一次执行用户定义的函数
- 如何在OMNET++中指定与命令行参数组合的输出文件名
- 为什么我的代码在输出中增加了93天
- "throw expression code" 1e7 >返回 d 是什么?投掷标准::overflow_error( "too big" ) : d;意味 着?
- 如何从void函数输出字符串
- 输入到文件并输出到另一个文件,并将流文件传递给函数
- AES加密到解密未正确输出
- 如何将c++程序的一些输出传递给shell,以便在shell中使用
- 使用C++程序合并排序没有得到正确的输出
- 为什么我不能在不创建字符串变量的情况下使用函数的字符串输出
- C++格式化输出问题
- "Program ended with exit code: 0"出现在我的输出的开头?
- 如何更改输出的位置或光标在输出处,以便在"Code Blocks"中C++
- Visual Studio Code输出被检测为恶意软件?
- VS Code C++程序在调试时不显示任何输出
- ofstream在极其简单的程序(GCC/Code::Blocks)中首次输出时崩溃