Thread: Colored text...?

  1. #1
    Registered User
    Join Date
    May 2003
    Posts
    15

    Colored text...?

    How do you do colored text in MSVC 6.0? Could anyone give me a little snippet of code that outputs say like "Hello" in a color? Thanks!

  2. #2
    Registered User
    Join Date
    Mar 2003
    Posts
    26
    are you talking about the color in the compiler or the color when you open the msdos window???

  3. #3
    Registered User
    Join Date
    May 2003
    Posts
    43
    Considering he wants code that will output "Hello" in a color, I'd say he wants it to have colored text in the dos window
    Programmer's Law:

    If your program doesn't work, look for the part that you didn't think was
    important.

  4. #4
    Registered User
    Join Date
    May 2003
    Posts
    15
    I would like it to say, output "Hello" in let's just say green text in the MSDOS console. Could someone please show me an example? I need it for my battleship game. ::Wink::Wink::.

  5. #5
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    You need to read the FAQ before posting these type of questions.
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  6. #6
    Registered User
    Join Date
    May 2003
    Posts
    15
    Awww...man sorry. I'm new to this forum as of today.

  7. #7
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    No harm done

    Welcome to cprog.com, enjoy your stay!
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  8. #8
    Registered User
    Join Date
    May 2003
    Posts
    195
    Here I made a Color File if you need it
    You must #include "colors.h" and colors.cpp
    Functions:
    Before everything you must do InitColor();
    then theres
    SetPosXY(x,y) <same thing as gotoxy;
    and then SetColor(FOREGROUND|BACKGROUND)
    SetPosXYAndColor(x,y,TEXT, COLOR)

  9. #9
    Registered User
    Join Date
    May 2003
    Posts
    195
    using that code, to write hello in color lets say green background red

    Code:
    #include <iostream.h>
    #include "colors.h"
    
    void main() {
           InitColor();
           SetColor(GREEN|BRED);
           cout<<"hello"<<endl;
    }

  10. #10
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    >>void main()
    Nice
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  11. #11
    S Sang-drax's Avatar
    Join Date
    May 2002
    Location
    Göteborg, Sweden
    Posts
    2,072
    I've alo created a color header for your convenience.

    It works together with cout:
    Code:
    #include <Petter-Color.h>
    #include <iostream>
    int main()
    {  
      using namespace std;
      using namespace Petter;
    
      cout << RED << "This is red.\n";
      cout << BLUE << "This is blue";
    }
    Last edited by Sang-drax : Tomorrow at 02:21 AM. Reason: Time travelling

  12. #12
    Banal internet user
    Join Date
    Aug 2002
    Posts
    1,380
    No return value in main()

    Nice

  13. #13
    Un Artiste Extraordinaire volk's Avatar
    Join Date
    Dec 2002
    Posts
    357
    When I leave out return 0, I usually get this warning:
    Code:
    warning C4508: 'main' : function should return a value; 'void' return type assumed
    You should always explicitly state return 0, unless, you know, you're a lazy programmer.

  14. #14
    Un Artiste Extraordinaire volk's Avatar
    Join Date
    Dec 2002
    Posts
    357
    Originally posted by vVv

    What your compiler has to say about it is totally meaningless. The Standard permits omitting it, that's what matters.


    It's not that meaningless. The compiler is letting you know that you're using an acceptable but lazy programming style.


    > You should always explicitly state return 0, unless, you know, you're a lazy programmer.

    The "should'' here is also meaningless, since it's completely a matter of style and nothing is mandating you to do it.
    The "should" in that sentence was just me imposing my style on everyone. Why can't you just accept that my style is simply awesome.

    Besides, you'll make the compiler shut up if you just put return 0.

    Do you leave out return 0 in your code, vVv, or were you just pointing out that "The Standard" allows it?

    Of course, I could just look at your code to answer that question, but I want you to work, kid!!!

  15. #15
    Un Artiste Extraordinaire volk's Avatar
    Join Date
    Dec 2002
    Posts
    357
    >(I suppose you're using some old DOS Borland crap compiler - get a better one).

    I'm using Microsoft Visual C++ 6.0.

    >Judging by your posts, I think you are 13 as well

    No, I'm an adult. Adults can have fun, too. No one told me those smiley faces and humor were reserved for kids only. Look at Hammer: he occasionally uses those smiley faces - and he's 40!

    LOL I hope he's not reading this.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How to use FTP?
    By maxorator in forum C++ Programming
    Replies: 8
    Last Post: 11-04-2005, 03:17 PM
  2. Colored Text in C
    By colorC in forum C Programming
    Replies: 4
    Last Post: 02-23-2004, 04:58 AM
  3. how to cout colored text?
    By Guanhui in forum C++ Programming
    Replies: 1
    Last Post: 07-05-2002, 08:14 AM
  4. 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
  5. Colored Text
    By Yoshi in forum A Brief History of Cprogramming.com
    Replies: 4
    Last Post: 11-28-2001, 09:46 AM