Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Color

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
Can any tell me how to use color in C++? I need text color especially.
 
What function are you calling to output your text?

Chip H.
 
OK, I had a look at the ios::flags in Visual Studio, and none of them specify how to set the color.

My first guess, (and this assumes you're on a IBM-compatible PC), is to reopen the stdio stream as a byte stream, and send the color attributes along with the text. There isn't any info in the MSDN what the color attributes are (they've removed all the old DOS reference info long ago), so you'll have to find an old DOS programming reference book (sorry, I don't have one any more). But, IIRC, it used the lowest 3 bits as foreground color, next highest 3 bits as background color, next 2 bits as blinking/underline codes.

Or, if this is a Windows program, you can call the Win32 GDI function called TextOut along with the SetTextColor function.

Or, if you're using MFC, call the ::SetTextColor of a CDC object, then call it's ::DrawText method.

Chip H.
 
There are some functions like cprintf, cscanf for color input/output operation. Functions are declared in conio.h.
Th set the needed color, you should use interruption 10h. If you want to use cout<<, you must overload the operator<<
ostream&amp; operator<<(ostream&amp;).
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top