Reputation: 51
I am currently working on a space invaders game in C++. I am trying to figure out a way to use only the standard library to create this game so that I can run it on Windows and Linux and get the same result.
So my question is this, can you program a console game in C++ using only the standard library that when compiled will run on both Windows and Linux?
Upvotes: 2
Views: 1989
Reputation: 14906
Easily, no.
There are terminal control codes, some of which are both supported under Windows, and UNIX.
There is some commonality and cross-over between the two. This would be a lot of work, and while I would be the first to admire such a work, I would doubt it would work well.
You're probably better off spending your time using something like the SDL library for cross-platform support. Maybe use SDL to make it look like a terminal, if that's a core requirement.
Even under various UNIX flavours (and terminals) the escape codes vary. The ncurses library hides a lot of this complexity.
Upvotes: 4
Reputation:
No. The C and C++ standard libraries do not contain any functions which perform any of the following tasks, all of which are critical for graphical console applications:
On Windows systems, these functions are available as part of the Console API. This API is Windows-specific, and is not usable on non-Windows systems.
On Linux and other UNIX systems, these functions are implemented within terminal emulators, and are often accessed using the ncurses library. This library is not available on Windows outside of non-native environments like Cygwin.
Upvotes: 2