Color Change Of text

How do i change color of text in the program more than once
rite now i use the code
1
2
3
4
system ("color 0c");//makes the color of the text red
cout <<"hey";
system ("color 02") //change color to green;
cout<<"only in green ";

it displays both the lines in green not the first in red and second in green.
Last edited on
http://www.cplusplus.com/forum/beginner/1640/

Here is a good topic (specifically the third post) that demonstrates the procedure for a Windows specific program. Windows is a pain in the butt and the API is difficult to use, but this will get the job done. The only downside is the lack of portability to other platforms.

I simplified the code slightly to remove anything that you don't need.
1
2
3
4
5
6
7
int main ()
{
  HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);

  SetConsoleTextAttribute(hConsole, FOREGROUND_BLUE | FOREGROUND_INTENSITY);
  cout << "This text should be blue" << endl;
}


http://msdn.microsoft.com/en-us/library/ms682088(VS.85).aspx#_win32_character_attributes
This is the Microsoft page that lists all of the different arguments that can be passed into the function to change the colors different way.
Topic archived. No new replies allowed.