user63898
user63898

Reputation: 30915

How to concatenate literal string and MACRO to valid string in c++

I have :

QString ver ="";
QString ver += "-svn-"SVN_REVISION

which yields an error pointing me to ver:

error: missing terminating " character
    ver += "-svn-"SVN_REVISION;

SVN_REVISION is defined as 1.

How can I concatenate them to be a valid string?

Upvotes: 0

Views: 417

Answers (2)

Pradhan
Pradhan

Reputation: 16737

You can use the preprocessor's stringify support as has been mentioned in the comments. Here's an example:

#define BASIC_STR(x) #x
#define STR(x) BASIC_STR(x)

QString ver ="";
QString ver += "-svn-" STR(SVN_VERSION);

Upvotes: 2

Marek R
Marek R

Reputation: 37927

QString ver = QString("-svn-%1").arg(SVN_REVISION);

Upvotes: 0

Related Questions