I wonder if I have something like this where Replace is the same as/"contains":
Number == 5.

My question is if it is possible to put this: Number == 5 to a std::string in any way through Replace ?

#define Replace Number == 5

>My question is if it is possible to put this: Number == 5
>to a std::string in any way through Replace ?
Do you mean you want to use Replace and get "Number == 5"? The short answer is no. If you want that, you need a separate define that does it for you:

#define ReplaceS "Number == 5"

If that's not what you mean, please elaborate.

U can like this "Number==5"

Thank you Narue.

This solution you came up with will work also :)
Just to confirm if I am thinking right. Is it correct that the std::string Word contains:
"Number == 5"

#define ReplaceS "Number == 5"

std::string Word;
Word = ReplaceS;

Thank you..


>My question is if it is possible to put this: Number == 5
>to a std::string in any way through Replace ?
Do you mean you want to use Replace and get "Number == 5"? The short answer is no. If you want that, you need a separate define that does it for you:

#define ReplaceS "Number == 5"

If that's not what you mean, please elaborate.

>you should take a look at: stringize and the token-pasting operators
As a general guideline, you should avoid the more advanced features of the preprocessor unless you have good reason not to.

>Is it correct that the std::string Word contains: "Number == 5"
Yes, your code is functionally identical to this:

std::string Word;
Word = "Number == 5";

> As a general guideline, you should avoid the more advanced features of the preprocessor unless you have good reason not to.

This made me curious why I should avoid it, I dont know to much of why I should.
Does anything goes slower or can something crash ?
The thing is for exactly the purpose I am doing now this is my only way to do it.
Thanks.


>you should take a look at: stringize and the token-pasting operators
As a general guideline, you should avoid the more advanced features of the preprocessor unless you have good reason not to.

>Is it correct that the std::string Word contains: "Number == 5"
Yes, your code is functionally identical to this:

std::string Word;
Word = "Number == 5";

>Does anything goes slower or can something crash ?
It's a ripe field for bugs, and debugging preprocessor errors is surprisingly difficult.

Okay, thank you. I will keep that in mind.

/j

>Does anything goes slower or can something crash ?
It's a ripe field for bugs, and debugging preprocessor errors is surprisingly difficult.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.