(1) print expression
When writing debugging code, writing a print expression consisting of a variable name and a string array followed by the variable name is boring. Fortunately, standard C has a string operator '#', the Preprocessor converts this parameter to an array of characters. Link this point with a combination of several characters without punctuations into a separate character array, which can generate a very convenient macro for printing the variable value during debugging:
# Define PR (x) cout <# X "=" <x <Endl;
Example:
//: C03: stringizingexpressions. CPP // from thinking in C ++, 2nd Edition // available at http://www.BruceEckel.com // (c) Bruce Eckel 2000 // copyright notice in copyright.txt # include <iostream> using namespace STD; # define P (a) cout <# A <":" <(a) <Endl; int main () {int A = 1, B = 2, C = 3; P (A); P (B); p (c); P (A + B); P (c-a)/B ); system ("pause ");}///:~