简体   繁体   English

为win32 && linux定义清除函数

[英]define clear function for win32 && linux

My question should not be too hard to answer: 我的问题应该不难回答:

I am trying to write a C program just to train up some C skills. 我试图编写一个C程序只是为了训练一些C技能。 However I can't tell on which system this program will run in the future. 但是我无法确定该程序将来将在哪个系统上运行。

I want to make sure I have covered both Unix and DOS systems. 我想确保我已经涵盖了Unix和DOS系统。

I am trying to do it like this: 我正在尝试这样做:

#ifdef _WIN32
   #define clear()
       system("cls");
#endif // _WIN32

#ifdef linux
    #define clear()
       system("clear");
#endif // linux

This seems to be wrong, as it tells me 这似乎是错误的,因为它告诉我

expected declaration specifiers or '...' before string constant"

Although I'm not sure if I am doing it right at all with this definitions (I could include 2 separate headers here for example >> more memory used) 尽管我不确定我是否对这个定义完全正确(例如,我可以在此处包括2个单独的标头,例如>>更多使用的内存)

There must be kind of a hard newbish syntax error here. 这里一定有一种很难的newbish语法错误。

Macro expansion should be on the same line as the macro name. 宏扩展应与宏名称位于同一行。 If you really want them over two lines, use \\ to "escape" the newline. 如果您确实希望它们超过两行,请使用\\ “转义”换行符。

#ifdef _WIN32
#define clear() system("cls");
#endif // _WIN32

#ifdef linux
#define clear() system("clear");
#endif // linux

or 要么

#ifdef _WIN32
#define clear() \
system("cls");
#endif // _WIN32

#ifdef linux
#define clear() \
system("clear");
#endif // linux

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM