Luxana
asked on
cout and color
Hello experts;
Is is possible in this small program cout my text in color?
#include<iostream>
using namespace std;
int main() {
cout << "This text has RED COLOR\n";
return 0;
}
so this text will apear on screen in red?
thanks
Is is possible in this small program cout my text in color?
#include<iostream>
using namespace std;
int main() {
cout << "This text has RED COLOR\n";
return 0;
}
so this text will apear on screen in red?
thanks
hi
no cout can't print in color unless you call OS specific functions
which OS are u using Windows ?
no cout can't print in color unless you call OS specific functions
which OS are u using Windows ?
ASKER
This is working but there is a problem with output
#include <stdio.h>
#include <windows.h>
void ChangeColour(WORD theColour)
{
HANDLE hConsole = GetStdHandle(STD_OUTPUT_HA NDLE); // Get handle to standard output
SetConsoleTextAttribute(hC onsole,the Colour); // set the text attribute of the previous handle
}
int main()
{
ChangeColour(FOREGROUND_BL UE); // Set the foreground colour to be blue
printf("This text is blue\n");
ChangeColour(FOREGROUND_RE D); // Set the foreground colour to be blue
printf("This text is red\n");
ChangeColour( FOREGROUND_BLUE | BACKGROUND_RED); // Set the foreground colour to be blue, the background to be red
printf("This is blue text on a red background\n");
ChangeColour(FOREGROUND_GR EEN); // Set the foreground colour to be green
printf("This text is blue\n");
return 0;
}
This text is blue
This text is red
This is blue text on a red background
This text is green
Press any key to continue <== this is green as well. I need this in standart colour otherwise everthing after this point will be green.
furqanchandio :
using g++ compiler as wel asi visual C++ ===> in this case prefered is visual c++
thanks for help
#include <stdio.h>
#include <windows.h>
void ChangeColour(WORD theColour)
{
HANDLE hConsole = GetStdHandle(STD_OUTPUT_HA
SetConsoleTextAttribute(hC
}
int main()
{
ChangeColour(FOREGROUND_BL
printf("This text is blue\n");
ChangeColour(FOREGROUND_RE
printf("This text is red\n");
ChangeColour( FOREGROUND_BLUE | BACKGROUND_RED); // Set the foreground colour to be blue, the background to be red
printf("This is blue text on a red background\n");
ChangeColour(FOREGROUND_GR
printf("This text is blue\n");
return 0;
}
This text is blue
This text is red
This is blue text on a red background
This text is green
Press any key to continue <== this is green as well. I need this in standart colour otherwise everthing after this point will be green.
furqanchandio :
using g++ compiler as wel asi visual C++ ===> in this case prefered is visual c++
thanks for help
well sounds pretty simple
ChangeColour(FOREGROUND_GR EEN); // Set the foreground colour to be green
printf("This text is blue\n");
ChangeColour(FOREGROUND_WH ITE); // this ought to do it, check for the white color
return 0;
cheers
ChangeColour(FOREGROUND_GR
printf("This text is blue\n");
ChangeColour(FOREGROUND_WH
return 0;
cheers
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
>well sounds pretty simple
>ChangeColour(FOREGROUND_G REEN); // Set the foreground colour to be green
> printf("This text is blue\n");
>ChangeColour(FOREGROUND_W HITE); // this ought to do it, check for the white color
> return 0;
>well sounds pretty simple
Well yes, and that was exactly first thing what I did. But it does not work. In fact I found that I'm able to use just RGB colors.
jaime_olivares:
your code is working without problems, great work and thanks for help.
./lubo
>ChangeColour(FOREGROUND_G
> printf("This text is blue\n");
>ChangeColour(FOREGROUND_W
> return 0;
>well sounds pretty simple
Well yes, and that was exactly first thing what I did. But it does not work. In fact I found that I'm able to use just RGB colors.
jaime_olivares:
your code is working without problems, great work and thanks for help.
./lubo
hi luxana
soory i tried to help you without getting my own hands dirty
but i hope my comments may have helped in you in way or another
cheers
soory i tried to help you without getting my own hands dirty
but i hope my comments may have helped in you in way or another
cheers
https://www.experts-exchange.com/questions/21111512/Cout-color.html