このコードを実行した後、ループが特定の数値以上になると、背景の色付けが崩壊することに気付きました。誰かがなぜそれを知っていますか? コード0-15と128 最初のパラメータから 整数をパラメータとして関数が取る これは着色関数TEXTCOLOR(パラメータ1、パラメータ2)であり、C++でC++の多くのループの後に背景の色が崩壊する!どうして?
#include <iostream>
using namespace std;
で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;
}
0をテストするためのメインプログラムこの行のために
New image only 1 textbackground color
互いに知り合わない2つの出力メカニズムを混在させています。 'cout'はおそらくWriteConsoleを使用せず、それがあったとしても、おそらくSetConsoleTextAttributeでバッファリングを調整していないでしょう。色を変更する前に 'cout'バッファをフラッシュしてみてください。 –
何も起こりません:( – kosnet2