How to change text color and console color in code::blocks?

后端 未结 8 1951
故里飘歌
故里飘歌 2020-12-08 17:29

I am writing a program in C. I want to change the text color and background color in the console. My sample program is -

#include 
#include &         


        
8条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-08 18:24

    I Know, I am very late but, May be my answer can help someone. Basically it's very Simple. Here is my Code.

    #include
    #include
    using namespace std;
    int main()
    {
        HANDLE colors=GetStdHandle(STD_OUTPUT_HANDLE);
    
        string text;
        int k;
        cout<<" Enter your Text : ";
        getline(cin,text);
        for(int i=0;i9 ? k=0 : k++;
    
            if(k==0)
            {
                SetConsoleTextAttribute(colors,1);
            }else
            {
                SetConsoleTextAttribute(colors,k);
            }
            cout<

    OUTPUT

    This Image will show you how it works

    If you want the full tutorial please see my video here: How to change Text color in C++

提交回复
热议问题