Monday, November 16, 2020

Text Color and Delay in C++ Using Dev C++

 I wrote this program to demonstrate how to use text color and delay in C++ using Dev C++ integrated development environment.

I am currently accepting programming work, IT projects, school and application development, programming projects, thesis and capstone projects, IT consulting work, computer tutorials, and web development work kindly contact me at the following email address for further details.  If you want to advertise on my website kindly contact me also in my email address also. Thank you.

My email address is the following jakerpomperada@gmail.com, jakerpomperada@aol.com, and jakerpomperada@yahoo.com.

My mobile number here in the Philippines is 09173084360.

My telephone number at home here in Bacolod City, Negros Occidental Philippines is  +63 (034) 4335675.

Here in Bacolod City I also accepting computer repair, networking, and Arduino Project development at a very affordable price. My website is www.jakerpomperada.blogspot.com and www.jakerpomperada.com

Thank you very much.




Program Listing

#include <iostream>

#include <windows.h>


using namespace std;


int main()

{

    HANDLE colors=GetStdHandle(STD_OUTPUT_HANDLE);


    string text;

    int a=0;

    text = "Master in Information Technology";

    cout << "\n\n";

    cout << "\tText Color and Delay in C++ Using Dev C++";

cout <<"\n\n";

    cout <<"\t";

    for(int i=0;i<text.length(); i++)

    {

        a>9 ? a=0 : a++;


        if(a==0)

        {

            SetConsoleTextAttribute(colors,1);

        }else

        {

            SetConsoleTextAttribute(colors,a);

        }

        cout<<text.at(i);

        Sleep(100);

    }

    cout << "\n\n";

    cout << "\tEnd of Program";

    cout << "\n\n";

}

4 comments:

  1. Hello! Is it possible for you to briefly explains on how it works? like why did you put:
    1) a=0
    2) for(int i=0;i9 ? a=0 : a++
    4) if(a==0)

    {

    SetConsoleTextAttribute(colors,1);

    }else

    {

    SetConsoleTextAttribute(colors,a);

    }

    cout<<text.at(i);

    Really curious on how it works as I'm doing for my programming projects haha

    ReplyDelete
    Replies
    1. HANDLE colors=GetStdHandle(STD_OUTPUT_HANDLE);
      This mean that now OS it self handle colors.

      a>9 ? a=0 : a++; it conditional operator we can use this in place of if-else.

      if(a==0) mean that color code is 1 which is blue

      Delete
    2. cout<<text.at(i); .at(i) is operation on string or it is function that reads string from specific index

      Delete
    3. Hello thank you for responding, the "at", what does it mean? Is there a name for it? Or is it a fixed function? Cause I don't see you use at anywhere on your program except for that one 🤔

      Delete