Search code examples
c++csyntaxincludeheader-files

Include multiple header-files at once with only one #include-expression?


Is there any expression possible for the syntax to include multiple headers at once, with no need to write the "#include"-expression for each file new?

Like, for example:

#include <stdio.h>, <stdlib.h>, <curses.h>, <string.h>  /* Dummy-Expression 1. */

OR

#include <stdio.h> <stdlib.h> <curses.h> <string.h>     /* Dummy-Expression 2. */

Question is for C AND C++.


Solution

  • No, there is no way to do this. You have to type out (or copy) each #include to its own line, like this:

    #include <stdio.h>
    #include <stdlib.h>
    #include <curses.h>
    #include <string.h>
    

    This applies to both C and C++.

    Some of the other answers discuss creating another header file that includes each of these, but I'm not going to discuss doing that. It in general is a bad idea and causes issues like namespace pollution and the need to recompile when you change that header file.