How to change text or background color in a Windows console application

前端 未结 3 927
后悔当初
后悔当初 2020-12-02 02:37

Which C++ function changes text or background color (MS Visual studio)? For example cout<<\"This text\"; how to make \"This text\" red color.

3条回答
  •  醉酒成梦
    2020-12-02 03:32

    I believe that you are looking for the SetConsoleTextAttribute function. The first parameter, hConsoleOutput, would be the standard output handle obtained via GetStdHandle(STD_OUTPUT_HANDLE). The second parameter is a bitwise-OR (|) combination of the desired character attributes.

    See also: KB319883 How to change foreground colors and background colors of text in a Console window by using Visual C#

提交回复
热议问题