|
|
C/C++ provides two preprocessor operators: # and ##. These operators are used in a #define macro.
The # operator causes the argument it precedes to be turned into a quoted string. For example, consider this program:
#include <iostream> using namespace std; #define mkstr(s) # s int main() { cout << mkstr(I like C++); return 0; }
The preprocessor turns the line
cout << mkstr(I like C++);
into
cout << "I like C++";
The ## operator is used to concatenate two tokens. For example, in the following program,
#include <iostream> using namespace std; #define concat(a, b) a ## b int main() { int xy = 10; cout << concat(x, y); return 0; }
the preprocessor transforms
cout << concat(x, y);
into
cout << xy;
If these operators seem strange to you, keep in mind that they are not needed or used in most programs. They exist primarily to allow some special cases to be handled by the preprocessor.
|
|