gha*_*hel 5 c system constants c-preprocessor
如果某些内容为真,我想定义一个常量,并在"system("")中使用它的值;
例如:
#ifdef __unix__
# define CLRSCR clear
#elif defined _WIN32
# define CLRSCR cls
#endif
int main(){
system("CLRSCR"); //use its value here.
}
Run Code Online (Sandbox Code Playgroud)
我知道clrscr();conio.h/conio2.h中有,但这只是一个例子.当我尝试启动它时,它表示cls未声明,或者CLRSCR不是内部命令(bash)
谢谢
Constant是一个标识符,而不是字符串文字(字符串文字有双引号;标识符没有).
另一方面,常量值是字符串文字,而不是标识符.你需要像这样切换它:
#ifdef __unix__
# define CLRSCR "clear"
#elif defined _WIN32
# define CLRSCR "cls"
#endif
int main(){
system(CLRSCR); //use its value here.
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
111 次 |
| 最近记录: |