Thread: How to change the color and clear the screen?

  1. #1
    Lariumentiko
    Guest

    How to change the color and clear the screen?

    1. How to change the color at the text? like
    Code:
    include <iostream.h>//which more files i need?
    
    int main(){
    
    changecolor//how to change the text color?
    cout << "This text is red..."; //... or should be
    return 0;
    }
    2. How to clear the screen? Example i make a "cout" saying "hello world". How then i clear the screen so it isnt there anymore?

  2. #2
    Registered User
    Join Date
    Nov 2002
    Posts
    1,109
    do a search, these topics have been discussed before. also, look at the FAQ.

  3. #3
    Registered User
    Join Date
    Dec 2001
    Posts
    479
    as alpha said do a search this have been asked before

    the things you wish to do depends on what compiler you have
    if u have borland its easier to change the colors but sorry i've forgot the name of the functions and headers, anyone with a good memory?
    the other thing clearing the screen i remember though?! i think..
    clrcs() was it right guys?
    in msvc include <stdlib.h>
    use the function system("cls")

  4. #4
    Registered User
    Join Date
    Jan 2003
    Posts
    648
    Since cout is a stream, it only handles data. It does not handle how it is displayed. So you can't change the color of cout. Not using a standard header at least.

    Windows can change the color of DOS-prompt when including some header. Real DOS can change colors using interrupts. Look it up.

  5. #5
    1.b4 e5 2.a3 d5 3.d4 exd
    Join Date
    Jan 2003
    Posts
    167
    Hi Im searching for how to do both of these possibilities, and unfortunately this is what I find. Anybody know how to do this?

  6. #6
    stovellp
    Guest
    Code:
    #include <windows.h>
    
    
    SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 0x000001);
    cout << "This text should be blue";
    The different numbers in the 0x000001 part change the colour, eg 0x00000f sets it to bright white.
    If SetConsoleTextAttribute() does not work, try SetConsoleTextAttributeA() (A on the end). I'm pretty sure that that is right.

    Code:
    #include <stdlib.h>
    system("cls");
    Is what I've always used, but I'm pretty sure theres some other functions for it, in CONIO.H somewhere.

    Paul

  7. #7
    the hat of redundancy hat nvoigt's Avatar
    Join Date
    Aug 2001
    Location
    Hannover, Germany
    Posts
    3,130
    Read the FAQ.
    hth
    -nv

    She was so Blonde, she spent 20 minutes looking at the orange juice can because it said "Concentrate."

    When in doubt, read the FAQ.
    Then ask a smart question.

Popular pages Recent additions subscribe to a feed