Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

how to change text colour of output in c++?

Posted on 2003-11-05
5
Medium Priority
?
537 Views
Last Modified: 2010-04-01
hello
      I have a problem while changing the colour of font in output
by using cout <<,
        please solve my problem and tell me how can i change the text colour n c++?
0
Comment
Question by:jadoogar
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
5 Comments
 

Accepted Solution

by:
Larn0s earned 80 total points
ID: 9693582
#include <iostream>
#include <windows.h>
#include <string>

using namespace std;

void DrawColorString(string szText, int X, int Y, WORD color);

int main(void) {

      DrawColorString("Red",  0, 0, FOREGROUND_RED);
      DrawColorString("White",5, 2, BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE);
      DrawColorString("Colored Text is Great!", 10, 4, FOREGROUND_RED | BACKGROUND_GREEN);

      return 0;
}

void DrawColorString(string szText, int X, int Y, WORD color) {

      HANDLE OutputH;
      COORD position = {X, Y};

      OutputH = GetStdHandle(STD_OUTPUT_HANDLE);
      SetConsoleTextAttribute(OutputH, color);
      SetConsoleCursorPosition(OutputH, position);

      cout << szText;
}
0
 
LVL 1

Expert Comment

by:Paladin_VB
ID: 9804542
.
0
 
LVL 1

Expert Comment

by:Paladin_VB
ID: 9804543
.
0
 
LVL 9

Expert Comment

by:tinchos
ID: 10242566
No comment has been added lately, so it's time to clean up this TA.
I will leave the following recommendation for this question in the Cleanup topic area:

Accept: Larn0s {http:#9693582}

Please leave any comments here within the next seven days.
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

Tinchos
EE Cleanup Volunteer
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
Article by: evilrix
Looking for a way to avoid searching through large data sets for data that doesn't exist? A Bloom Filter might be what you need. This data structure is a probabilistic filter that allows you to avoid unnecessary searches when you know the data defin…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question