繁体   English   中英

为win32 && linux定义清除函数

[英]define clear function for win32 && linux

我的问题应该不难回答:

我试图编写一个C程序只是为了训练一些C技能。 但是我无法确定该程序将来将在哪个系统上运行。

我想确保我已经涵盖了Unix和DOS系统。

我正在尝试这样做:

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

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

这似乎是错误的,因为它告诉我

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

尽管我不确定我是否对这个定义完全正确(例如,我可以在此处包括2个单独的标头,例如>>更多使用的内存)

这里一定有一种很难的newbish语法错误。

宏扩展应与宏名称位于同一行。 如果您确实希望它们超过两行,请使用\\ “转义”换行符。

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

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

要么

#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