hello. I'm doing a program in c++ and I need to use a system call to "clear" my screen.
for linux I use system("clear") but in windows the same is system("clr").
is there some way to find which OS is being used at the moment of execution so the program can decide whether it should use "clear" ou "clr"?
thanks in advance :)
onemanclapping
0
Light Poster
Recommended Answers
Jump to PostThere is no way to determine what OS the program is running on. Perhaps make two functions, and if say the windows function fails, run the Linux function.
Jump to PostThe best way to do this would be know what OS your program will be working on. I think if you put the Windows call in a function and set it to return a bool true if successful and false if not (using an if statement) then you would be …
Jump to PostThe program must know what operating system its running under because it has to be recompiled for each os. Add some sort of preprocessor directive that tells the program what os its being compiled for. For example, you might put the define _WIN32 in the makefile when compiled for MS-Windows …
Jump to PostThe best way to do this would be know what OS your program will be working on. I think if you put the Windows call in a function and set it to return a bool true if successful and false if not (using an if statement) then you would be …
Jump to Postfor example on Linux you could compile using
g++ -D_LINUX file.cpp -o output # turns on the #define _LINUX
and on windows using
g++ -D_WIN32 file.cpp -o output #turns on #define _WIN32
So if you had a makefile on both systems, you could set your compiler …
All 21 Replies
dmanw100
36
Posting Whiz in Training
onemanclapping
0
Light Poster
dmanw100
36
Posting Whiz in Training
Ancient Dragon
5,243
Achieved Level 70
Team Colleague
Featured Poster
Ancient Dragon
5,243
Achieved Level 70
Team Colleague
Featured Poster
onemanclapping
0
Light Poster
Ancient Dragon
5,243
Achieved Level 70
Team Colleague
Featured Poster
Duoas
1,025
Postaholic
Featured Poster
onemanclapping
0
Light Poster
Sci@phy
97
Posting Whiz in Training
skatamatic
371
Practically a Posting Shark
skatamatic
371
Practically a Posting Shark
ArkM
1,090
Postaholic
Duoas
1,025
Postaholic
Featured Poster
onemanclapping
0
Light Poster
Ancient Dragon
5,243
Achieved Level 70
Team Colleague
Featured Poster
stilllearning
148
Posting Whiz
Ancient Dragon
commented:
Exactly what I had in mind :)
+36
Duoas
1,025
Postaholic
Featured Poster
ArkM
1,090
Postaholic
jmichae3
Ancient Dragon
5,243
Achieved Level 70
Team Colleague
Featured Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.