Put color in output and Make it faster!

I have researched a c++ code that outputs a dialog. It outputs the dialog in different color for every letter and changes the background to white.

What i want is to make it output just a single color, specifically color yellow and the backgroud should be black in order for the user to see it clearly. Also, i want to make it output faster. How would i do this?

Here is the code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37

#include <conio.h>
#include <iostream>
#include <string>
#include <windows.h>

using namespace std;

HANDLE console = GetStdHandle(STD_OUTPUT_HANDLE); 

void WaitKey();

int main()
{

	int len = 0,x, y=240; 
	string text = "WELCOME USER!!";
	len = text.length();
	cout << endl << endl << endl << "\t\t"; 
	for ( x=0;x<len;x++)
	{
		SetConsoleTextAttribute(console, y); 
		cout << text[x];
		y++; 
		if ( y >254)
			y=240;
		Sleep(250); 
	}

	SetConsoleTextAttribute(console, 16); 
	
        cin.get();
	cin.get();
	
	return 0;
}
Last edited on
1
2
3
4
5
6
7
8
9
10
11
12
13
#include <iostream>
#include <windows.h>
using namespace std;

int main()
{

	system("Color 0E");
	std::cout << "\t\t\t    Hello World" << std::endl;

	cin.ignore();
	return 0;
}


I should probably mention that system is generally frowned upon, but its probably the easiest way to accomplish this
http://www.cplusplus.com/articles/j3wTURfi/
Last edited on
thanks for that. but can you make the dialog appear as what the code above have done?.i,e., every letter will not appear simultaneously but rather one after another..?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include <iostream>
#include <cstring>
#include <Windows.h>
using namespace std;

int main()
{
	char text[] = "Hello World";
	system("Color 0E");

	for (int i = 0; i < strlen(text); i++)
	{
		cout << text[i];
		Sleep(200);
	}

	cin.ignore();
	return 0;
}
Last edited on
thank you so much. you are great!
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#include <iostream>
#include <string>
#include <windows.h>

int main()
{
    const WORD FG_BRIGHT_YELLOW = FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_INTENSITY ;
    const WORD FG_DARK_GREY = FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE ;

    const HANDLE console = GetStdHandle(STD_OUTPUT_HANDLE) ;
    const std::string text = "WELCOME USER!!" ;
    const DWORD DELAY = 125 ;


    SetConsoleTextAttribute( console, FG_BRIGHT_YELLOW ) ;
    std::cout << "\n\n\n\t\t";

    for( std::size_t i = 0  ; i < text.size() ; ++i )
    {
        std::cout << text[i] << std::flush ;
        Sleep(DELAY) ;
    }

    SetConsoleTextAttribute( console, FG_DARK_GREY ) ;
    std::cin.get();
}
Topic archived. No new replies allowed.