10'000 行后控制台中的 C++ 背景颜色错误
c++ wrong background colors in console after 10'000 lines
打印出比"屏幕缓冲大小"高度的线多(默认情况下为300,最多最多为9999(。第一白线的其余部分具有黄色背景。信息连续显示并突出显示重要部分,因此system("cls")
不是首选选项。还有其他解决方案吗? Windows 7,MSVS社区2017,x86&x64
#include "Windows.h"
#include "stdio.h"
class Console {
HANDLE h;
public:
Console() { h = GetStdHandle(STD_OUTPUT_HANDLE); }
void ChangeColor(WORD wColor) {
if (h != INVALID_HANDLE_VALUE) SetConsoleTextAttribute(h, wColor);
}
} console;
int main() {
for (int i = 0;; i += 4) {
console.ChangeColor(224);
printf("highligted yellow, line = %5dn", i);
console.ChangeColor(240);
printf("plane whitennn");
if (i % 1000 == 0) getchar();
}
}
我认为控制台缓冲区被重复使用,并且您设置的颜色属性会与新线路混乱。您应该分配黑色并分别处理EOL。
for (int i = 0;; i += 4)
{
console.ChangeColor(224);
printf("highligted yellow, line = %d", i);
console.ChangeColor(0);
printf("n");
console.ChangeColor(240);
printf("plane white");
console.ChangeColor(0);
printf("nnn");
if (0 == (i % 1000)) getchar();
}
相关文章:
- 如何在全屏模式下(在OpenGL中)使背景透明
- 使用窗口中的QSlider更改背景音量
- SDL2 透明背景
- 在 Visual C++ 中以编程方式更改按钮的背景图像
- 多重采样背景不显示
- 直接2D用WM_ERASEBKGND擦除背景?
- 在特定时间内更改 QLabel 的背景颜色
- 如何设置与其背景图像大小相对应的窗口大小?
- 更改包含 QButton 的 Qlayout 的背景颜色
- 如何为使用创建窗口创建的窗口创建自定义背景颜色
- 删除K的背景掩码-意味着Python或C++中的集群/
- SystemParametersInfo将背景设置为纯色,而不是实际设置图片
- 背景任务UWP C++只触发一次
- 我正在尝试更改背景的颜色,但它不起作用
- 在 C 中获取背景外壳命令的 PID
- 如何在QT中为QInputDialog输入密码时设置背景非活动和灰色?
- MFC 更改 CListCtrl 背景颜色
- 如何仅设置 QTabWidget 背景颜色样式表
- Qt为所有对话框设置通用背景
- 什么是"MFC Dialog Extension"?(Windows/C++ 新手 - Linux 背景)