Q:

#include anywhere

Is the #include <file> meant to be used for headers only or is it simply a mechanical "inject this code here" that can be used anywhere in the code?
What if I use it in the middle of a cpp function to just "inject" code from a single source? will this work or will compilers scream about this?

A:

It is a mechanical inject the code here device. You can include a text file containing Goethe's Faust if you wish to. You can put it anywhere, even in the middle of a function (of course, #include needs a fresh line!).
However, it's strong convention to only use #include for header files. There may be reasons where I wouldn't object on it, for example pulling in machine-generated code or merging all translation units in a single file.

A:

Not only does it work anywhere, but it can lead to some interesting techniques. Here's an example that generates an enumeration and a corresponding string table that are guaranteed to be in sync.
Animals.h:
ANIMAL(Anteater)
ANIMAL(Baboon)
...
ANIMAL(Zebra)

AnimalLibrary.h:
#define ANIMAL(name) name,

enum Animals {
#include "Animals.h"
        AnimalCount
    };

#undef ANIMAL

extern char * AnimalTable[AnimalCount];

AnimalLibrary.cpp:
#include "AnimalLibrary.h"

#define ANIMAL(name) #name,

char * AnimalTable[AnimalCount] = {
#include "Animals.h"
    };

main.cpp:
#include "AnimalLibrary.h"

int main()
{
    cout << AnimalTable[Baboon];
    return 0;
}

Be sure not to put the usual include guards in any file that will be included multiple times!
Gotta agree with William Pursell though that this technique will have people scratching their heads.

A:

It will work - more or less its semantic meaning is: place code in that file here
EDIT: For abusing usages of #include I can just recommend the following:
#include "/dev/console"

This allows for everything: a one-liner that can do everything, an error, its just a matter of compilation...

