Is there a way to use operator+ to concatenate std::strings in c++? -


this question has answer here:

i have function this

void foo (const char* mystring){ ... } 

and want use this

std::string tail = "something"; foo("my" + "string" + tail); 

but can't find easy way. sure can make string somewhere else , pass foo(). prefer find way inline, because foo() called several times in code, don't want make string each time. tried

foo(std::string ("my" + "string" + tail).c_str()) 

but can guess doesn't work.

"my"and "string" c style string literals, have odd rule concatenated if written without +.

so "my" "string" + tail work, , produce std::string. however, still not correct type function, unless use .c_str() on result.


Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -