I'm writing a program, and I would like to output different types of debugging information depending on the value of various macro variables (so that I can change the value of a flag that then causes different levels of information to be written to the screen).
For example, suppose I have the following code that prints information to the screen about my program (call this D1):
cout << "% Percentage complete: "
<< ceil((static_cast<double>(idx)/static_cast<double>(ITERATIONS))*(100.00))
<< "%" << endl;
cout << "x = [ x; ";
for(int i=0; i<space.getDimension(); i++)
cout << visited.vec[visited.bestIndex].x[i] << "\t";
cout << "];" << endl;
Now, also suppose I have the following code that prints different information to the screen about my program (call this D2):
cout << "best = [ best; "
<< visited.vec[visited.bestIndex].meanQALY() << "];\n" << endl;
space.displayConstraintsMATLAB(idx+1);
I would like to be able to insert statements such as #D1
and #D2
at certain places in my code and have the macro processor replace these statements with the above code blocks.
How can I do this?
(I'm happy to hear suggestions for different ways of doing this, if macros are not an ideal solution.)