Jump to content
  • Advertisement
Sign in to follow this  
FxMazter

Concat strings?

This topic is 4856 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi! It has been a while since I did some c++ :) If I remember correctly I could concatenate two strings like this: #define STR1 "Hello" #define STR2 " World" STR1 "Want to concatenate with" STR2 So that I can write something like this: STR1\@STR2 which would equal to "Hello World" where \@ is the symbol for concatenation I don't want to create a string object for this... Thx!

Share this post


Link to post
Share on other sites
Advertisement
Create a string large enough to hold both of them and then assign "hello" to the first and use strcat.

or

Make them both std::strings and just use the += operator.

Share this post


Link to post
Share on other sites
In your specific case [where you are using string literals], you don't need any symbol. STR1 STR2 will result in "Hello World" as you would expect.

This fails if either of STR1 and STR2 are variables, of course.

CM

Share this post


Link to post
Share on other sites
I'm not exactly sure what you're trying to do, but in C++ if you have two string literals seperated by nothing but whitespace, they will automatically be concatenated, so STR1 STR2 will work fine ("Hello" " World"). #defines probably aren't such a good idea for this. A const std::string object would probably get optimized out by the compiler to be as though it were a literal.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!