Как сделать, чтобы чёрного не было на цветной консоли(т. е. буквы остались красными и сзади был цвет консоли)?

Нужно, чтобы буквы остались красными, а фон был в цвет консоли

int main() {
srand(time(NULL)); 
HANDLE console = GetStdHandle(STD_OUTPUT_HANDLE);
CONSOLE_SCREEN_BUFFER_INFO start_attribute;               
GetConsoleScreenBufferInfo(console, &start_attribute);
int n;
cin >> n;
int i, j;       

int **sarray;   
sarray = new int *[n];
for (i = 0; i < n; i++) { 
    sarray[i] = new int[n]; 
}

for (i = 0; i < n; i++) {
    for (j = 0; j < n; j++) { 
        sarray[i][j] = rand() % 101 - 50;
    }
}
for (i = 0; i < n; i++) {  
    for (j = 0; j < n; j++) {
        SetConsoleTextAttribute(console, FOREGROUND_RED);
        cout << setw(3) << sarray[i][j] << " ";
    } 
    cout << endl;
}
SetConsoleTextAttribute(console, start_attribute.wAttributes);
cout << endl << "modified array:" << endl << endl;
for (i = 0; i < n; i++) {
    for (j = 0; j < n; j++) {
        if (j > i) {
            sarray[i][j] = 0; 
        }
    }
}
for (i = 0; i < n; i++) {  
    for (j = 0; j < n; j++) {
        if (i == j) {
            SetConsoleTextAttribute(console, 32);
            cout << setw(3) << sarray[i][j] << " ";
        }
        else {
            SetConsoleTextAttribute(console, 228);
            cout << setw(3) << sarray[i][j] << " ";
        }
    }
    cout << endl;
    SetConsoleTextAttribute(console, start_attribute.wAttributes);
}
SetConsoleTextAttribute(console, start_attribute.wAttributes);

}


Ответы (0 шт):