Search
 
SCRIPT & CODE EXAMPLE
 

CPP

c++ rainbow text

`enter code here`#include <stdafx.h> // Used with MS Visual Studio Express. Delete line if using something different
#include <conio.h> // Just for WaitKey() routine
#include <iostream>
#include <string>
#include <windows.h>

using namespace std;

HANDLE console = GetStdHandle(STD_OUTPUT_HANDLE); // For use of SetConsoleTextAttribute()

void WaitKey();

int main()
{

    int len = 0,x, y=240; // 240 = white background, black foreground 

    string text = "Hello World. I feel pretty today!";
    len = text.length();
    cout << endl << endl << endl << "		"; // start 3 down, 2 tabs, right
    for ( x=0;x<len;x++)
    {
        SetConsoleTextAttribute(console, y); // set color for the next print
        cout << text[x];
        y++; // add 1 to y, for a new color
        if ( y >254) // There are 255 colors. 255 being white on white. Nothing to see. Bypass it
            y=240; // if y > 254, start colors back at white background, black chars
        Sleep(250); // Pause between letters 
    }

    SetConsoleTextAttribute(console, 15); // set color to black background, white chars
    WaitKey(); // Program over, wait for a keypress to close program
}


void WaitKey()
{
    cout  << endl << endl << endl << "			Press any key";
    while (_kbhit()) _getch(); // Empty the input buffer
    _getch(); // Wait for a key
    while (_kbhit()) _getch(); // Empty the input buffer (some keys sends two messages)
}
Comment

PREVIOUS NEXT
Code Example
Cpp :: (/~/+|/+$/g, ') 
Cpp :: void does not a name a type in cpp 
Cpp :: c++ server service ros 
Cpp :: Call db.close() on Button_Click (QT/C++) 
Cpp :: hello command not printing in c++ 
Cpp :: amusia 
Cpp :: how to call subclass override method in c++ 
Cpp :: c++ ascii value 
Cpp :: c++ cout 
Cpp :: random c++ 
Cpp :: vector remove class 
Cpp :: conditions in c++ 
Cpp :: longest increasing subsequence nlogn c++ 
Cpp :: c++ destructor 
Cpp :: decrement c++ 
Cpp :: set elements to 42 back 
Cpp :: make an x using asterisk c++ 
C :: find string in all files powershell 
C :: arduino wifi ip address to string 
C :: sstf program in c 
C :: same project on different monitor in intellij mac 
C :: prime chec kin c 
C :: thread in c 
C :: convert number to string c 
C :: concatenate char * c 
C :: how to login to another user in powershell 
C :: sequelize count multiple associations 
C :: c program to print the multiplication table 
C :: what is syntax in programming 
C :: vowel and consonant C 
ADD CONTENT
Topic
Content
Source link
Name
1+4 =