I'm creating a simple game with my friend that runs in the Terminal/Command Prompt window, but I would like to know how to change the color of the entire window via C++. I'm on a Mac, but my friend is on a Windows, so I need to a solution that is portable, if possible. Thank you so much for replies!
P/S: I've tried using a printf statement to change the color, but it only changes the background color of the text being printed.
PP/S: I know the solution is out there, but no matter how much Googling I do, all the answers seem to be Windows only.
For starters, the console is a terrible medium for games. Consider getting a graphic lib like SFML. On top of being much, much easier, you'll be able to draw whatever you want to the screen and it also is portable and can run on both Mac and Windows:
Secondly, nothing in the C++ standard lib allows you to change the color of the console. Anything you do is going to be platform specific (ie: it'll work on Windows and not Mac, or vice versa. Nothing will work on both).
The only way to do this on both Mac/PC is one of the following:
1) Do it in a Windows specific way, and also in a Mac specific way, and use #ifdefs to determine whether or not you're building on Mac/Windows.
or
2) Get a lib like NCurses which wraps console I/O through a portable interface.
Though if you're going to go through the trouble of getting a lib like NCurses... you might as well just get a graphic lib like SFML and abandon the console entirely.
Thank you so much, Disch, your answer was very helpful! I had been looking into trying SFML, but for some reason hadn't. I'm going to try it out now though.