How to set the color of a single word without changing the color of all the text?

I would like to know how to change the color of text. I know how to do something like:

system("color 0a")

Which would change the color of all displayed characters to a light green. However, is it possible to write a sentence in C++ that outputs as:

Hello world, I am user3554369!

Where all of the text is white except "username3554369," which would be green?

It does not have to be cross-platform. Assume all users will be running Windows.

Thanks!

Upvotes: 0

Views: 2702

Answers (1)

zmbq
zmbq

Reputation: 39013

Check the second answer here: http://www.cplusplus.com/forum/beginner/5830/ .

It uses the SetConsoleTextAttribute Windows API function, which seems to be a much better idea than using system().

Upvotes: 1

Related Questions