Thread: Text Color

  1. #1
    I Like Red
    Guest

    Text Color

    Hi,

    I'm inexperienced with C++, and am wondering how to change the color of the text. I am using MS Visual C++ and the output is simple and DOS-like. Unless specified, the color of the text is white, though I'm trying to change it to red. I have searched for hours on-line to no avail. I have found textcolor(), settextcolor, etc., but have not found how to use them in a simple program that does not involve graphics or windows (as opposed to DOS-like). Thanks for any help.

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    This has been answered, try using a board search.

    -Prelude
    My best code is written with the delete key.

  3. #3
    Registered User abrege's Avatar
    Join Date
    Nov 2002
    Posts
    369
    Easy

    Code:
    HANDLE hOutput = GetStdHandle(STD_OUTPUT_HANDLE);
    
    SetConsoleTextAttribute(hOutput, FOREGROUND_RED);
    
    cout << "This would be red";
    
    SetConsoleTextAttribute(hOutput, FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE);
    
    cout << "This would be white again";
    I am against the teaching of evolution in schools. I am also against widespread
    literacy and the refrigeration of food.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. GUI Text Color Problem
    By justlivelife15 in forum Windows Programming
    Replies: 3
    Last Post: 06-25-2007, 05:47 AM
  2. Change text color in C
    By IndioDoido in forum C Programming
    Replies: 9
    Last Post: 04-15-2007, 05:54 AM
  3. Critique my lighting model.
    By psychopath in forum Game Programming
    Replies: 4
    Last Post: 08-12-2006, 06:23 PM
  4. Color text from windows.h?
    By Saintdog in forum C++ Programming
    Replies: 10
    Last Post: 12-03-2004, 09:20 AM
  5. Ok, Structs, I need help I am not familiar with them
    By incognito in forum C++ Programming
    Replies: 7
    Last Post: 06-29-2002, 09:45 PM