system("color F0"); 

Change the color of the console this line, the question is this. How after specific manipulations to restore the default color of the console?

    1 answer 1

    system("color F0"); - considered to be incorrect using system();

    Do not tell people to use system (). If you are going to do something right.

    Original source
    And the code is right way

     #include <iostream> #include <windows.h> int main() { const WORD colors[] = { 0x1A, 0x2B, 0x3C, 0x4D, 0x5E, 0x6F, 0xA1, 0xB2, 0xC3, 0xD4, 0xE5, 0xF6 }; HANDLE hstdin = GetStdHandle( STD_INPUT_HANDLE ); HANDLE hstdout = GetStdHandle( STD_OUTPUT_HANDLE ); WORD index = 0; // Remember how things were when we started CONSOLE_SCREEN_BUFFER_INFO csbi; GetConsoleScreenBufferInfo( hstdout, &csbi ); // Tell the user how to stop SetConsoleTextAttribute( hstdout, 0xEC ); std::cout << "Press any key to quit.\n"; // Draw pretty colors until the user presses any key while (WaitForSingleObject( hstdin, 100 ) == WAIT_TIMEOUT) { SetConsoleTextAttribute( hstdout, colors[ index ] ); std::cout << "\t\t\t\t Hello World \t\t\t\t" << std::endl; if (++index > sizeof(colors)/sizeof(colors[0])) index = 0; } FlushConsoleInputBuffer( hstdin ); // Keep users happy SetConsoleTextAttribute( hstdout, csbi.wAttributes ); return 0; } 

    Similar question on stackoverflow

    If you really need ... to set the default value, then setColor(8 , 15);
    I hope helped!

    • Counterquestion. What to do if you need to change the background of the entire console and not just under the text? - user239757
    • setColor(0, 15); - 0 - black background, 15 - white letters. - Brave_Lime