I have this function that gets 3 input(mostly LPCSTR) and combines them together and finally return the value:
template<typename T>
inline T const& LPCombine(T const& lpStr1, T const& lpStr2, T const& lpStr3)
{
std::string str1, str2, str3, Combined;
LPCSTR lpCombiend = "";
str1 = lpStr1;
str2 = lpStr2;
str3 = lpStr3;
Combined = str1 + str2 + str3;
lpCombiend = Combined.c_str();
return lpCombiend;
}
If I print the value of lpCombined in the same function it's correct and strings or numbers are concatenated so well but If I print the returned value from the LPCombine function from another function like the main function the printed value is something weird and unreadable:
╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠
What is the problem?
Twould itself be a pointer type, which would have the same problem.c_stris only guaranteed to last as long asCombined, so it getsdeleted after the end of the function asCombineditself is being destroyed.