I currently have a function that I want to return a single string, but I want it to return all elements of a string array in a single string which the function can return. Any advice is appreciated.
Asked
Active
Viewed 65 times
-1
-
Use `std::stringstream` from `#include
` to concatenate your strings. – zneak May 05 '14 at 03:44 -
http://stackoverflow.com/questions/5689003/how-to-implode-a-vector-of-strings-into-a-string-the-elegant-way – Darius Houle May 05 '14 at 03:45
-
3Please show what, if any, code you have tried. – R Sahu May 05 '14 at 03:45
-
@zneak Thank you, this is exactly what I was looking for, it worked great. – user3483203 May 05 '14 at 03:46
1 Answers
0
You can just do like this:
string f()
{
string s1 ="Hello ";
string s2 = "world!";
stringstream ss;
ss<< s1;
ss<< s2;
return ss.str();
}
Rakib
- 7,215
- 6
- 27
- 44