This question already has an answer here:
I wish I could edit a variable in a .h file since compilation Example:
#include <iostream> #include <stdlib.h> #define HOST (char *)"http://localhost/" #define PATH "insert"
I want to edite HOST
from compilation like this:
g++ -o output source.cpp -HOST http://mywebsite/
You can easily do that with something like this:
#include <iostream> #include <stdlib.h> #ifndef HOST #define HOST (char*)"http://localhost/" #endif #define PATH "insert"
Then, on the command-line, you either specify '-DHOST=(char*)"whatever"'
(and it will be used), or do not pass in any -DHOST=
flag, and the default in the header will be used.