0

hi!

i want to print a colored 'A' using putchar, let's say green.
i am able to print * by doing just putchar('A');
but i don't know that how to print a colored 'A'.
i have also tried to write:

putchar('A',255);

and also

putchar('A',3);

but no success.

3
Contributors
3
Replies
4
Views
6 Years
Discussion Span
Last Post by embooglement
0

Doing things like that is generally operating system dependent, so you'll need to look at the documentation for your OS's API to see if/how it supports something like that.

0

This is an example.

#include <string>

void color(){

cout << "write a number" << endl;
string color;
cin >> color;


system( ("color "+color).c_str() );

}

Edited by alexchen: n/a

1

This is an example.

#include <string>

void color(){

cout << "write a number" << endl;
string color;
cin >> color;


system( ("color "+color).c_str() );

}

That will work provided whatever OS sajid1 is using supports that; not all do. However, at least on windows, that does not write a character with a color. That sets the color scheme for the entire console, including any characters that have already been written, and those that will be written later.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.