1

Based on the user-defined numeric macro PROBNO, I want to include a file "prob[PROBNO].hpp", and run the function of the same name, prob[PROBNO](). The problem here is that I need the quotes around the included file, as < > gives me a file not found error. I'm currently doing the 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 does the job, but it looks messy. is there any way I can get rid of some of the directives somehow?

tomatopipps
  • 299
  • 2
  • 13
  • You don't need token concatenation to produce a filepath, and using concatenation can result in (unnecessary) compiler errors. Not using concatenation will simplify your macros. See http://stackoverflow.com/a/32077478/1566221 for an example and more explanation. – rici Feb 06 '16 at 20:29

1 Answers1

1

Use angles instead of quotes:

#define PROBNAME <prob PROBNO.h>

#include PROBNAME
Cecilio Pardo
  • 1,717
  • 10
  • 13