-
July 10th, 2009, 03:23 PM
#1
[RESOLVED] String manipulation
I'm coming from a c# environment and I was wondering something instead of doing things on multiple lines...how to do it in one
example: [C#]
Code:
string foo="LOL";
string bar="zie lime";
foo+=" at " +bar + " all the time";
//output : "LOL at zie lime all the time"
I've tried that with std::string and just gives me a bunch of errors saying essentially that the + doesn't belong there
I was wondering if it's possible to do the same thing but in c++
right now I'm doing
[C++]
Code:
//lets say they are declared
foo+=" at ";
foo+=bar;
foo+= "all the time";
which makes the code really heavy
-
July 10th, 2009, 04:24 PM
#2
Re: String manipulation
It works fine so long as the leftmost expression is a std::string. In your case, it's not----" at " has type const char*. This is a legacy from C, mainly.
You can solve it like so:
Code:
string foo="LOL";
string bar="zie lime";
foo+=string(" at ") +bar + " all the time";
-
July 10th, 2009, 06:41 PM
#3
Re: String manipulation
thanks works gr8
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|