C++ color dynamic problem

This is a discussion on C++ color dynamic problem within the C++ Programming forums, part of the General Programming Boards category; I need the ability to change text color dynamically within a page without using the clear screen command clrscr();. I ...

  1. #1
    Registered User
    Join Date
    Oct 2002
    Posts
    12

    C++ color dynamic problem

    I need the ability to change text color dynamically within a page without using the clear screen command clrscr();. I do know that this works:

    Code:
     cout << "The last word in this sentence is ";
    textcolor(RED);
    cprintf("red");
    textcolor(LIGHTGRAY);
    but I need to be able to output dynamic variables this way too, like this, but it does not work:

    Code:
     int var;
    cout << "Give var a value: ";
    cin >> var;
    cout << "In var, you inputted the number ";
    textcolor(RED);
    cprintf(var);
    textcolor(LIGHTGRAY);
    So why? and how can I get it work? Did I miss something? thanks

  2. #2
    Refugee face_master's Avatar
    Join Date
    Aug 2001
    Posts
    2,052
    try converting var to a string using itoa() then doing it.
    Code:
    int var = 10;
    char var_str[20];
    itoa(var, var_str, 10);
    Last edited by face_master; 10-05-2002 at 06:35 PM.

  3. #3
    Registered User
    Join Date
    Oct 2002
    Posts
    12
    Originally posted by face_master
    try converting var to a string
    Wow, thats fast response. Thanks but how? I m new to C++ so how can I convert from var to string? Can you give me short example or where to change?

    many thanks!

  4. #4
    Refugee face_master's Avatar
    Join Date
    Aug 2001
    Posts
    2,052
    >> Wow, thats fast response.

    Cprogramming never close so I never leave. Well, I will in around 2.5 hours casue i gotta go to work for 4 hours!
    Last edited by face_master; 10-05-2002 at 07:07 PM.

  5. #5
    Registered User
    Join Date
    Oct 2002
    Posts
    12
    lol, I see

    I try and couldnt convert, thanks anyway.

  6. #6
    Registered User
    Join Date
    Oct 2002
    Posts
    12
    Ok, problem solved!! Thread closed? I guess.. thanks!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need help understanding a problem
    By dnguyen1022 in forum C++ Programming
    Replies: 2
    Last Post: 04-29-2009, 05:21 PM
  2. Memory problem with Borland C 3.1
    By AZ1699 in forum C Programming
    Replies: 16
    Last Post: 11-16-2007, 11:22 AM
  3. Someone having same problem with Code Block?
    By ofayto in forum C++ Programming
    Replies: 1
    Last Post: 07-12-2007, 09:38 AM
  4. A question related to strcmp
    By meili100 in forum C++ Programming
    Replies: 6
    Last Post: 07-07-2007, 03:51 PM
  5. WS_POPUP, continuation of old problem
    By blurrymadness in forum Windows Programming
    Replies: 1
    Last Post: 04-20-2007, 07:54 PM

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