I am a newbie in c++. I know this is a very common question, but I want a complete code to concat any number of strings which are passed to function in c++. I am calling the function as:
string var1,var2;
var1=concat_string("one","two");
cout<<var1<<endl;
var2=concat_string("one","two","three");
cout<<var2<<endl;
My required output is:
onetwo
onetwothree
I have read about variadic function, but I tried the following code to concatenate strings without worrying of the result size and number of string arguments. My code is:
#include <cstdarg>
template<typename... T>
string concat_string(T const&... t){
std::stringstream s;
s<<t;
return s;
}
But I got lots of error in this code. How can I correct my code. Thanks..