text color

This is a discussion on text color within the C++ Programming forums, part of the General Programming Boards category; how do i change the color in c++?...

  1. #1
    Registered User
    Join Date
    May 2002
    Posts
    3

    text color

    how do i change the color in c++?

  2. #2
    Still A Registered User DISGUISED's Avatar
    Join Date
    Aug 2001
    Posts
    499
    Search the boards, this has been discussed many many times.

  3. #3
    Unregistered
    Guest
    Lol, I find it sad how little people can be bothered to search for a topic, before they post about it.

    if (topic already discussed) {read it's thread/s/;}
    else{post new thread;}

  4. #4
    Unleashed
    Join Date
    Sep 2001
    Posts
    1,765
    > Lol, I find it sad how little people can be bothered to search for a topic, before they post about it.

    > Search the boards, this has been discussed many many times.

    Apparently by the same person:
    http://www.cprogramming.com/cboard/s...threadid=17889
    The world is waiting. I must leave you now.

  5. #5
    Registered User
    Join Date
    May 2002
    Posts
    63
    include conio.h

    syntax: textcolor(RED); // makes the text colour red

    read the conio.h file for more colours which you can use

    Enjoy
    tudehopet uses Borland Compiler 5.5
    and Visual C++ 6.

  6. #6
    Unleashed
    Join Date
    Sep 2001
    Posts
    1,765
    I did exactly that -

    > textcolor(RED); // makes the text colour red
    Just like that, without quotes:
    tmp.c: In function `main':
    tmp.c:6: `RED' undeclared (first use in this function)
    tmp.c:6: (Each undeclared identifier is reported only once
    tmp.c:6: for each function it appears in.)
    With quotes textcolor("RED");
    c:\windows\TEMP\ccT8FYfb.o(.text+0x1c):tmp.c: undefined reference to `textcolor'
    Thanks for the portable code, I really enjoyed it.
    The world is waiting. I must leave you now.

  7. #7
    I am the worst best coder Quantrizi's Avatar
    Join Date
    Mar 2002
    Posts
    644
    you also have to include conio.c

  8. #8
    Registered User
    Join Date
    May 2002
    Posts
    63
    Sorry for that.
    I think it is compiler specific.
    I use borland compiler 5.5

    As for the "RED" in inverted comma's, that is actually a value in an enum. ie enum COLORS {RED;};
    this makes RED = 0;
    but don't type that in.

    I think if you edit the conio.h file, look for the enum COLORS, I assume by the errors you are using Dev-C++, if there is enum COLORS the you should see a list of colours which you can choose from.

    I hope that this works
    tudehopet uses Borland Compiler 5.5
    and Visual C++ 6.

  9. #9
    Unleashed
    Join Date
    Sep 2001
    Posts
    1,765
    > you also have to include conio.c
    I've never had to do this.
    I don't even have a conio.c.

    > , I assume by the errors you are using Dev-C++,
    I use gcc.
    The world is waiting. I must leave you now.

  10. #10
    Registered User
    Join Date
    May 2002
    Posts
    63
    Well gcc is actually the what Dev-C++ uses to compile its source code. So it should use the same include files.

    Just have a look at the conio.h file for the enum COLORS.
    tudehopet uses Borland Compiler 5.5
    and Visual C++ 6.

  11. #11
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    This has been asked and answered countless times. Here's the Windows version that I use for this question:
    Code:
    #include <iostream>
    #include <windows.h>
    using namespace std;
    
    int main ( void )
    {
      HANDLE h;
      h = GetStdHandle ( STD_OUTPUT_HANDLE ); 
      SetConsoleTextAttribute ( h, FOREGROUND_RED | FOREGROUND_GREEN ); 
      cout<<"The ";
      SetConsoleTextAttribute ( h, FOREGROUND_RED );
      cout<<"search ";
      SetConsoleTextAttribute ( h, FOREGROUND_GREEN );
      cout<<"feature ";
      SetConsoleTextAttribute ( h, FOREGROUND_INTENSITY | FOREGROUND_BLUE );
      cout<<"is ";
      SetConsoleTextAttribute ( h, FOREGROUND_INTENSITY | FOREGROUND_RED );
      cout<<"very ";
      SetConsoleTextAttribute ( h, FOREGROUND_INTENSITY | FOREGROUND_GREEN );
      cout<<"useful. ";
      SetConsoleTextAttribute ( h, FOREGROUND_INTENSITY | FOREGROUND_BLUE | FOREGROUND_RED );
      cout<<"Use ";
      SetConsoleTextAttribute ( h, FOREGROUND_BLUE | FOREGROUND_GREEN );
      cout<<"it!"<<endl;
      SetConsoleTextAttribute(h, FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_RED);
      return EXIT_SUCCESS;
    }
    -Prelude
    My best code is written with the delete key.

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, 08: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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21