1`enter code here`#include <stdafx.h> // Used with MS Visual Studio Express. Delete line if using something different
2#include <conio.h> // Just for WaitKey() routine
3#include <iostream>
4#include <string>
5#include <windows.h>
6
7using namespace std;
8
9HANDLE console = GetStdHandle(STD_OUTPUT_HANDLE); // For use of SetConsoleTextAttribute()
10
11void WaitKey();
12
13int main()
14{
15
16 int len = 0,x, y=240; // 240 = white background, black foreground
17
18 string text = "Hello World. I feel pretty today!";
19 len = text.length();
20 cout << endl << endl << endl << "\t\t"; // start 3 down, 2 tabs, right
21 for ( x=0;x<len;x++)
22 {
23 SetConsoleTextAttribute(console, y); // set color for the next print
24 cout << text[x];
25 y++; // add 1 to y, for a new color
26 if ( y >254) // There are 255 colors. 255 being white on white. Nothing to see. Bypass it
27 y=240; // if y > 254, start colors back at white background, black chars
28 Sleep(250); // Pause between letters
29 }
30
31 SetConsoleTextAttribute(console, 15); // set color to black background, white chars
32 WaitKey(); // Program over, wait for a keypress to close program
33}
34
35
36void WaitKey()
37{
38 cout << endl << endl << endl << "\t\t\tPress any key";
39 while (_kbhit()) _getch(); // Empty the input buffer
40 _getch(); // Wait for a key
41 while (_kbhit()) _getch(); // Empty the input buffer (some keys sends two messages)
42}