Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Nov 2008
    Location
    Australia
    Posts
    13
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Colored Output in C++

    I was recently writing a program for windows that implemented a colored output, done with code:

    Code:
    void setcolor(unsigned short color)                 //The function that you'll use to
    {                                                   //set the colour
        HANDLE hcon = GetStdHandle(STD_OUTPUT_HANDLE);
        SetConsoleTextAttribute(hcon,color);
    }
    now i plan to port this program across to Macintosh using xCode but there doesn't appear to be an include file that allows me to do so.
    Any suggestions?

    b.t.w my include files
    Code:
    #include <iostream>
    #include <time.h>
    #include <cstdlib>
    #include <windows.h>

  • #2
    Rockstar Coder
    Join Date
    Jun 2002
    Location
    USA
    Posts
    9,074
    Thanks
    1
    Thanked 328 Times in 324 Posts
    SetConsoleTextAttribute is a Windows API call and as such won't exist elsewhere. In order to change the color of a Unix terminal, you need to send terminal commands. They just go in the output, the terminal recognizes them and will let you change the color.
    OracleGuy

  • #3
    New Coder
    Join Date
    Nov 2008
    Location
    Australia
    Posts
    13
    Thanks
    1
    Thanked 0 Times in 0 Posts
    whats is the command that you have to send to the terminal?


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •