Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums
Old 05-28-2003, 11:07 AM   #1 (permalink)
zergmuncher
Registered User
 
zergmuncher's Avatar
 
Join Date: May 2003
Location: CA
Posts: 12
zergmuncher is on a distinguished road
Send a message via AIM to zergmuncher
I hate to ask...

I need to print text to the screen in color. I'm having a hard time using cprintf (see a previous post)(I need it to print a string). Is there any way that I can get cout to print color? If not, what is the easiest...umm...my train of thought just disrailed...oh yeah, what's the easiest print function that I can use to print a string in color? Thank you guys very much!
zergmuncher is offline   Reply With Quote
Old 05-28-2003, 08:48 PM   #2 (permalink)
Danish
Registered User
 
Join Date: Mar 2003
Posts: 12
Danish is on a distinguished road
Send a message via AIM to Danish
I'm assuming you want to do this in Windows? Check the gametutorials page http://www.gametutorials.com/Tutorials/c++/Cpp_Pg4.htm.

But here's the function on that page. I haven't tried it, but it'll probably work.
Code:
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;
}
You will probably want to check the file anyway, as they comment those lines to tell you what each one's doing.

Oh, yeah, and make sure you #include <windows.h>

And cprintf() CAN print strings. Here's the general idea:
Code:
string my_string;
...
cprintf("%s", my_string.c_str());
...
That is what you meant, right?
Danish is offline   Reply With Quote
Old 05-29-2003, 09:20 AM   #3 (permalink)
zergmuncher
Registered User
 
zergmuncher's Avatar
 
Join Date: May 2003
Location: CA
Posts: 12
zergmuncher is on a distinguished road
Send a message via AIM to zergmuncher
I'm not sure if that's what I meant (I'm retarded right now), but it works, so I'm happy. Will this work with iomanip? (please say yes), cuz I need to have columns of a standard width for this to look halfway decent...I could just do it using a spacing thing, but that'd be really annoying...I know I keep asking you guys for help, and I'm probably getting to be a pain in the :butt: , so...yeah, I'll shut up now. Thank you guys for your help
zergmuncher is offline   Reply With Quote
Old 05-29-2003, 10:21 PM   #4 (permalink)
Danish
Registered User
 
Join Date: Mar 2003
Posts: 12
Danish is on a distinguished road
Send a message via AIM to Danish
Well, um, did you TRY iomanip with this? Did you have any problems? It should work... *confused*
Danish is offline   Reply With Quote
Old 08-14-2003, 10:53 AM   #5 (permalink)
bluedevils1414
Registered User
 
Join Date: Aug 2003
Location: sd.ca.us
Posts: 29
bluedevils1414 is on a distinguished road
..
bluedevils1414 is offline   Reply With Quote
Old 08-14-2003, 10:58 AM   #6 (permalink)
bluedevils1414
Registered User
 
Join Date: Aug 2003
Location: sd.ca.us
Posts: 29
bluedevils1414 is on a distinguished road
,,
bluedevils1414 is offline   Reply With Quote
Old 08-14-2003, 10:59 AM   #7 (permalink)
bluedevils1414
Registered User
 
Join Date: Aug 2003
Location: sd.ca.us
Posts: 29
bluedevils1414 is on a distinguished road
//
bluedevils1414 is offline   Reply With Quote
Old 08-14-2003, 11:01 AM   #8 (permalink)
bluedevils1414
Registered User
 
Join Date: Aug 2003
Location: sd.ca.us
Posts: 29
bluedevils1414 is on a distinguished road
;;
bluedevils1414 is offline   Reply With Quote
Old 08-14-2003, 11:01 AM   #9 (permalink)
bluedevils1414
Registered User
 
Join Date: Aug 2003
Location: sd.ca.us
Posts: 29
bluedevils1414 is on a distinguished road
\\
bluedevils1414 is offline   Reply With Quote
Old 08-14-2003, 11:02 AM   #10 (permalink)
bluedevils1414
Registered User
 
Join Date: Aug 2003
Location: sd.ca.us
Posts: 29
bluedevils1414 is on a distinguished road
''
bluedevils1414 is offline   Reply With Quote
Old 08-14-2003, 12:32 PM   #11 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,529
sde is on a distinguished road
last warning.
__________________
Mike
sde is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -8. The time now is 01:41 PM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0 RC8





Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting