Hello
Whats the shortest/easiest way to do the following thing with std::string:
Is it possible to do this in one line statement?Code:std::string r; r = somestr + "@" + somestr2;
Hello
Whats the shortest/easiest way to do the following thing with std::string:
Is it possible to do this in one line statement?Code:std::string r; r = somestr + "@" + somestr2;
Code:std::string r(somestr + "@" + somestr2);
7. It is easier to write an incorrect program than understand a correct one.
40. There are two ways to write error-free programs; only the third one works.*
I believe that will only work if the left-most string in the + concatenation sequence is a std::string (or has an equivalent operator+() ).
Yes, if somestr is some other type such as a char[], you'd have to use something like
That would be the shortest way, but perhaps not the easiest. This might be easier:Code:std::string r(std::string(somestr) + "@" + somestr2);
Code:std::string r = somestr; r += "@"; r += somestr2;
dwk
Seek and ye shall find. quaere et invenies.
"Simplicity does not precede complexity, but follows it." -- Alan Perlis
"Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
"The only real mistake is the one from which we learn nothing." -- John Powell
Other boards: DaniWeb, TPS
Unofficial Wiki FAQ: cpwiki.sf.net
My website: http://dwks.theprogrammingsite.com/
Projects: codeform, xuni, atlantis, nort, etc.