Freerobots
Freerobots

Reputation: 772

In C++, is it possible to use a string literal as a macro name?

Here's my scenario: I have a set of source files that I'd prefer to not modify, but I'd like to replace some of the string literals with other values. Here's an example:

#define "oldString" "newString"

Upvotes: 2

Views: 220

Answers (2)

Donnie
Donnie

Reputation: 46943

No, #define allows you to give a value to an identifier. Identifiers can't contain the quote character.

Upvotes: 5

casablanca
casablanca

Reputation: 70731

No, that's not possible. If you had already used macros in place of the strings, it would have been simple to change the macro definition to use a different string -- better late than never, you might want to do it now.

Upvotes: 5

Related Questions