473,394 Members | 1,797 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

How to make C++ code Portable?

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
1 1995
weaknessforcats
9,208 Expert Mod 8TB
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

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

Similar topics

7
by: Tom | last post by:
How can I make code not execute for a debug build, but do execute for a production build? I have code which prompts for an account and password when the program starts up. It is a pain to have to...
131
by: pemo | last post by:
Is C really portable? And, apologies, but this is possibly a little OT? In c.l.c we often see 'not portable' comments, but I wonder just how portable C apps really are. I don't write...
2
by: JebBushell | last post by:
I have an existing page, that works, and I'm trying to enhance it by adding a dropdown in a datagrid. When I add the dropdown, I expect the code-behind file to be updated by VS. It should be...
1
by: beachboy | last post by:
My project has many class (function), it need to create a new instance each time by the id value, how can i write a code as much simple? Actually, all cases is doing the same thing.... , but is...
9
by: Jim Langston | last post by:
This is something I've been thinking about creating, and am trying to get the pieces together. I want to be able to assign values in a method accepting different types. I.E. ...
239
by: Eigenvector | last post by:
My question is more generic, but it involves what I consider ANSI standard C and portability. I happen to be a system admin for multiple platforms and as such a lot of the applications that my...
5
by: P | last post by:
I was wondering what sort of changes I need to make in order to make an application to be DEP compatible with on Windows XP x64 version 2003. I have compiled an open source C application...
2
by: James | last post by:
I am doing some Excel 2000 automaton using Vb 2005. I am referencing the Excel 9.0 COM Object Library. The following code was working fine: Dim xlApp as new Excel.Application Dim xlWb as...
2
by: nagpal | last post by:
i want to make a c code to solve quine mclunsky method of getting reduced expression how shall i start
3
by: zr | last post by:
Hi, Does usage of checked iterators and checked containers make code more secure? If so, can that code considered to be reasonably secure?
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.