文字背景颜色更改后C 中的许多循环崩溃!为什么
Text Background Color Changing Collapses after many loops in C++! Why?
运行此代码后,我注意到,如果循环超过特定数字,背景着色崩溃了。一个人知道为什么吗?代码在C
中#include <iostream>
using namespace std;
这是着色函数TextColor(参数1,参数2)该功能作为参数0-15和128的整数数字第一个参数用于Fontcolor和第二个参数用于背景颜色
#include <Windows.h>
#define BLACK 0
#define BLUE 1
#define GREEN 2
#define CYAN 3
#define RED 4
#define MAGENTA 5
#define BROWN 6
#define LIGHTGREY 7
#define DARKGREY 8
#define LIGHTBLUE 9
#define LIGHTGREEN 10
#define LIGHTCYAN 11
#define LIGHTRED 12
#define LIGHTMAGENTA 13
#define YELLOW 14
#define WHITE 15
#define BLINK 128
HANDLE screen = GetStdHandle(STD_OUTPUT_HANDLE);
void TextColor(int fontcolor, int backgroundcolor)
{
int color_attribute;
color_attribute = backgroundcolor;
color_attribute = _rotl(color_attribute, 4) | fontcolor;
SetConsoleTextAttribute(screen, color_attribute);
}
//测试着色功能的主要程序
int main()
{
int counter = 1;
while(counter<=50)
{
TextColor(0, 15);
int i = 0, j;
while (i <= 5)
{
j = 1;
while (j <= 28)
{
cout << " ";
j++;
}
cout << endl;
i++;
}
TextColor(15, 0);
cout << endl << endl << endl;
counter++;
}
system("pause");
return 0;
}
新图像仅1层面颜色
为此行:
TextColor(0, counter%20);
如果唯一的有效颜色在0-15之间,那么当counter%20
表达式评估为16-19之间时,您期望发生什么?
相关文章:
- 如何循环打印顶点结构
- 如何在C++中从两个单独的for循环中添加两个数组
- C++我的数学有什么问题,为什么我的代码不能正确循环
- 正在尝试了解输入验证循环
- std::map<struct,struct>::find 找不到匹配项,但是如果我循环通过 begin() 到 end(),我在那里看到匹配项
- 循环后如何继续阅读
- Ardunio UNO解决了多个重叠的定时器循环
- Eigen如何在容器循环中干净地附加矩阵
- 在某些循环内使用vector.push_back时出现分段错误
- 我正在使用嵌套的while循环来解析具有多行的文本文件,但由于某种原因,它只通过第一行,我不知道为什么
- 为什么我的for循环不能正确获取argv
- 如何声明特征矩阵,然后通过嵌套循环初始化它
- while循环中while循环的时间复杂度是多少
- C++中的高效循环缓冲区,它将被传递给C样式数组函数参数
- 为什么在这个代码结束循环中没有得到结束
- 使用 for 循环在 c++ 中写入许多文件
- 视觉 在C++中,我试图在没有递归的情况下循环访问许多对象
- 许多变量,没有嵌套循环的最佳方法
- 文字背景颜色更改后C 中的许多循环崩溃!为什么
- 基于范围的'for'循环是否弃用了许多简单的算法?