Thread: colored variable output

  1. #1
    1.b4 e5 2.a3 d5 3.d4 exd
    Join Date
    Jan 2003
    Posts
    167

    colored variable output

    ok, i can make colored DOS text like so...but how can I output a varible int x in that color? Is it bad to use cout and cprintf in the same program? somebody said it was but why?

    textcolor(LIGHTCYAN);
    cprintf(" ********************* \r\n")
    AIM: MarderIII

  2. #2
    Registered User abrege's Avatar
    Join Date
    Nov 2002
    Posts
    369
    IMHO, it looks abnormal to interchange c and c++ style output I have no idea what textcolor() is, here is what I'd do in MSVC

    Code:
    #include <windows.h>
    
    ....
    
    HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);
    
    int x = 5;
    
    SetConsoleTextAttribute(hOut, FOREGROUND_INTENSITY | FOREGROUND_BLUE);
    
    cout << x;
    I am against the teaching of evolution in schools. I am also against widespread
    literacy and the refrigeration of food.

  3. #3
    Registered User
    Join Date
    Jan 2003
    Posts
    14
    I had to do this once, and my solution probably isnt the best one but here:

    1. Change the variable to a string by itoa(int, char *string, base) where base 10 is what we use normally.


    2.change textcolor using function textcolor(?)

    3.use cprintf to print the string.

    you do this because i dont think u can change the color of a variable ( at least on my compiler)
    ~fin

  4. #4
    1.b4 e5 2.a3 d5 3.d4 exd
    Join Date
    Jan 2003
    Posts
    167
    how do u print a string with cprintf()?
    AIM: MarderIII

  5. #5
    1.b4 e5 2.a3 d5 3.d4 exd
    Join Date
    Jan 2003
    Posts
    167
    itoa(num2, char *num2char, base);

    the above doesnt work, not sure what this is supposed to look like
    AIM: MarderIII

  6. #6
    Registered User Cela's Avatar
    Join Date
    Jan 2003
    Posts
    362
    >>itoa(num2, char *num2char, base);
    >>the above doesnt work, not sure what this is supposed to look like
    You probably don't have itoa() since it's not a standard function. Use sprintf instead :-)
    Code:
    sprintf(str, "%d", number);
    *Cela*

  7. #7
    Registered User
    Join Date
    Jan 2002
    Posts
    387
    is cprintf() the same as printf()?

    if so,
    cprintf("%d", number);
    "There are three kinds of people in the world...
    Those that can count and those that can't."

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  2. Connecting input iterator to output iterator
    By QuestionC in forum C++ Programming
    Replies: 2
    Last Post: 04-10-2007, 02:18 AM
  3. why this output?
    By dredre in forum C Programming
    Replies: 4
    Last Post: 05-08-2004, 04:09 PM
  4. Store command output into a variable.
    By Kevin.j in forum C Programming
    Replies: 7
    Last Post: 09-29-2002, 11:44 AM
  5. Variable Allocation in a simple operating system
    By awkeller in forum C Programming
    Replies: 1
    Last Post: 12-08-2001, 02:26 PM