# and ## [C++ Reference]
Keywords: preprocessor,sharp
Date: 2009-09-22T14:27:00-0700

[[# and ##]]
C++ Reference
Translations of this page?:

- en
- br-pt
- cn
- cz
- de
- es
- fr
- it
- jp
- nl
- pl
- ro
- ru
- sk
- tr
- tw

## # and ##

The # and ## preprocessor operators are used with the #define preprocessor directive.

- Using # causes the first argument after the # to be returned as a string in quotes.
- Using ## concatenates what's before the ## with what's after it.

For example, the command

         #define to_string( s ) # s

will make the compiler turn this command

         cout << to_string( Hello World! ) << endl;

into

         cout << "Hello World!" << endl;

Here is an example of the ## command:

         #define concatenate( a, b ) a ## b
         ...
         int xy = 10;
         ...

This code will make the compiler turn

         cout << concatenate( x, y ) << endl;

into

         cout << xy << endl;

which will, of course, display '10' to standard output.

Related topics: #define

Edit this page • Old revisions
• • • Login • Index • Recent changes • RSS • cc •