简体   繁体   English

C ++中的头文件

[英]header files in C++

In my C++ code, I want to include many header files that are placed in one folder. 在我的C ++代码中,我想要包含许多放在一个文件夹中的头文件。 how can i include them all at once? 我怎么能一次把它们全部包括在内?

Create a header file that includes them all and include that instead. 创建一个包含所有头文件的头文件,并将其包括在内。

Ie, I know of no compiler that has this functionality built in, and if one did it would certainly be non-standard functionality. 即,我知道没有内置此功能的编译器,如果有人这样做,肯定会是非标准功能。

Execute the following shell commands in the directory which holds your .h files: 在包含.h文件的目录中执行以下shell命令:

rm -f meta.h
echo "#ifndef META_H" >> meta.h
echo "#define META_H" >> meta.h
for h in `ls *.h`; do echo "#include \"$h\"" >> meta.h; done
echo "#endif /*META_H*/" >> meta.h

...and then #include "meta.h" alone. ......然后#include“meta.h”一个人。

You may wrap them in a helping header file. 您可以将它们包装在帮助头文件中。 Having created it once, you can include it everywhere. 创建一次后,您可以随处include它。

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

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