c++ - Is there a more succinct way to include a file based on a macro defining part of its name? -
based on user-defined numeric macro probno, want include file "prob[probno].hpp", , run function of same name, prob[probno](). problem here need quotes around included file, < > gives me file not found error. i'm doing following:
#define stringify2(x)#x #define stringify(x)stringify2(x) #define concat2(x,y)x##y #define concat(x,y)concat2(x,y) #define probname concat(prob,probno) #include stringify(probname.hpp) #include<iostream> int main(){ std::cout<<probname()<<'\n'; } this job, looks messy. there way can rid of of directives somehow?
use angles instead of quotes:
#define probname <prob probno.h> #include probname
Comments
Post a Comment