O'Reilly logo

Sams Teach Yourself C++ in 24 Hours, Third Edition by Jesse Liberty

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

String Manipulation

The preprocessor provides two special operators for manipulating strings in macros. The stringizing operator (#) substitutes a quoted string for whatever follows the stringizing operator. The concatenation operator (##) bonds two strings together into one.

Stringizing

The stringizing operator(#) puts quotes around any characters following the operator, up to the next white space. So, if you write:

#define WRITESTRING(x) cout << #x

and then call

WRITESTRING(This is a string);

the precompiler will turn it into this:

cout << "This is a string";

Note that the string This is a string is put into quotes, as required by cout.

Concatenation

The concatenation operator (##) enables you to bond together more than one term into ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required