macro stringization merge

Hi!

I have a problem with below code:
1
2
3
4
5
6
7
8
9
10
#include <iostream>
using namespace std;

#define MISSION(x) "Apollo_" ## #x

int main()
{
        cout <<  MISSION(12) << endl;
        return 0;
}

prog.cpp:8:1: error: pasting ""Apollo_"" and ""12"" does not give a valid preprocessing token
My compiler - gcc version 4.4.5

I want to get output like "Apollo_12"
Try this -> #define MISSION(x) "Apollo_" #x

MISSION(12) will expand to "Apollo_" "12", which is the same as "Apollo_12".

Note that ## is used for concatenating preprocessing tokens, not strings.
Last edited on
It's work and I understood how work "##".
Thank you for your help ;)
Topic archived. No new replies allowed.