color text

hi , i need to know how to change color of text . i tried but no goood . my actual program is too big so i will give small code by which u can tell me how can i change its color .
this is what i was trying , it is just an example . plz tell me whole procedure how to do it , by the way i am using turbo c++ 3.5 OR i have borland c++ 4.5

1
2
3
4
5
6
7
8
9
 #include<iostream.h>
#include<conio.h>
#include<dos.h>
void main()
{
      textcolor(5);
      cout<<"help";
getche();
}
closed account (Dy7SLyTq)
first dont use dos. secondly use iostream instead of iostream.h. thirdly use int main. fourthly http://www.cplusplus.com/articles/Eyhv0pDG/ however if your on a linux system i recommend ncurses. of couse since your on windows you can use windows.h
i already told u i am working on turbo c++ 3.5
plz tell me solution according to it
thanks
closed account (Dy7SLyTq)
what are you talking about? it doesnt matter that thats your compiler. i gave you a solution
i went to that link but no good , it is giving me errors .
#include<eku\io\concol.h> error
Last edited on
closed account (Dy7SLyTq)
im pretty sure you have to make the .h file your self while i bet you just #included it, but whatever. try this:

#include <Windows.h>
#include <iostream>

using namespace std;

int main(void)
{
HANDLE hStdout = GetStdHandle(STD_OUTPUT_HANDLE);
if (hStdout == INVALID_HANDLE_VALUE)
{
cout << "Error while getting input handle" << endl;
return EXIT_FAILURE;
}
//sets the color to intense red on blue background
SetConsoleTextAttribute(hStdout, FOREGROUND_RED | BACKGROUND_BLUE | FOREGROUND_INTENSITY);

cout << "This is intense red text on blue background" << endl;
//reverting back to the normal color
SetConsoleTextAttribute(hStdout, FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE);

return EXIT_SUCCESS;
}
thanks
;-)
Last edited on
closed account (Dy7SLyTq)
^not a smart idea at all
@jayssj11

Here was my answer to changing text and background colors, which I believe, is easier to know what colos are being assigned.
http://v2.cplusplus.com/forum/beginner/99434/
Does what you've provided not change the colour?

If conio.h is really an appropriate header then it looks like it should work, have you tried some other values?

EDIT: Try outputting the text with cprintf, textcolor might require you use one of conio.h's own printing functions.
Last edited on
DTSCode, iostream may not be available for his platform, it sounds like he's programming for DOS...

If he's programming for DOS let him program for DOS!
closed account (Dy7SLyTq)
if he doesnt have iostream and has to use dos.h then he needs some new software.

If he's programming for DOS let him program for DOS!

thats like saying: if hes making bad mistakes, let him make those!
Sometime's I'm tempted to tell people programming for Windows that they're making a bad mistake, but I restrain myself. :P
closed account (Dy7SLyTq)
programming for windows is not a bad mistake. using old headers is
@DTSCode
You are really being belligerent about the OP's platform. Go away.

@jayssj11
The code you posted does not work when you compile and run it?

The issue might be that the Borland runtime is trying to access the video buffer directly. Read in the documentation to see how to turn that off. (I think there is a boolean variable you can toggle.) Otherwise you'll need to flag your program to run as a legacy application (from Explorer, right click and play with the stuff under the "Compatability" tab).

Good luck!
Topic archived. No new replies allowed.