c++ - How can I #include a file whose name is built up from a macro? -
On a cross-platform project, I want to include a # header file named after the platform, There is a #define macro for.
For example,
#define PLATFORM win32
I want
#include For "engine \ win32 \ devices_win32.h"
#define PLATFORM linux
I want to
#include "engine \ linux \ devices_linux.h"
I'm going with Richard Pennington's answer, zero to one line code - It works for me!
#define PLATFORM Linux #define xstr (x) #x #define str (x) xstr (x) #define sub (x) x #include str (sub (engine / platform / device_ ) PLATFORM.h)
#define PLATFORM Linux #define xstr (x ) #x #define str (x) xstr (x) #define sub (x) x #define FILE str (sub / engine / platform / devices_) platforms h) #include FILE
I'm not sure if I use it, though. ;-) I had to use linux instead of linux because Linux is defined as 1 in my compiler.
Comments
Post a Comment