I want to define a constant if something is true, and use its value inside a "system("");
For example:
#ifdef __unix__
# define CLRSCR clear
#elif defined _WIN32
# define CLRSCR cls
#endif
int main(){
system("CLRSCR"); //use its value here.
}
I know there is clrscr();
in conio.h/conio2.h but this is just an example. And when I try to launch it, it says cls
is not declared, or that CLRSCR is not a internal command (bash)
Thanks
Constant is an identifier, not a string literal (string literals have double quotes around them; identifiers do not).
Constant value, on the other hand, is a string literal, not an identifier. You need to switch it around like this:
#ifdef __unix__
# define CLRSCR "clear"
#elif defined _WIN32
# define CLRSCR "cls"
#endif
int main(){
system(CLRSCR); //use its value here.
}
You need this:
#ifdef __unix__
#define CLRSCR "clear"
#elif defined _WIN32
#define CLRSCR "cls"
#endif
system(CLRSCR); //use its value here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With