By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,949 Members | 1,302 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,949 IT Pros & Developers. It's quick & easy.

How to make C++ code Portable?

P: 4
I am doing a group project that sometimes is going to be tested under Linux operating system but some function like
system("cls") only works on windows. I found a answer here says to use a header file:
Expand|Select|Wrap|Line Numbers
  1. // #define LINUX
  2. // #define WINDOWS
  3. // #define OSX
  4.  
then add this in the source file
Expand|Select|Wrap|Line Numbers
  1. #ifdef LINUX
  2. char os[] = "Linux";
  3. #else
  4. #ifdef WINDOWS
  5. char os[] = "Windows";
  6. #else
  7. char os[] = "Mac OSX";
  8. #endif
  9. #endif
  10.  
I just want to check if there a easier way to do, I am using GCC compiler.
Thank you.
Sep 15 '10 #1
Share this Question
Share on Google+
1 Reply


weaknessforcats
Expert Mod 5K+
P: 9,197
The system() call should work in Linux but I believe the arguments to system() are OS dependent. That is, "cls" may only work on Windows and some things that work on Linux won't work on Windows.
Sep 16 '10 #2

Post your reply

Sign in to post your reply or Sign up for a free account.