c++concatenationlpcstr

How to Concatenate Two LPCSTRs


I have two LPCSTRs I need to concatenate like so:

if (!rename(directory + originalFileName, directory + fileName)){
    std::cout<<originalFileName<<std::endl<<fileName<<std::endl<<std::endl;
}

The only problem however is that I can't use the + operator here. How can I safely concatenate two LPCSTRs like this?

EDIT: Note that an LPCSTR is defined as a const * char while an LPCTSTR is defined as const TCHAR*. The two are different when UNICODE and/or _UNICODE are defined. In this case, they are.


Solution

  • Thanks to WhozCraig, I got the answer:

    LPCSTR str1 = "foo",
           str2 = "bar";
    
    std::string(str1).append(str2).c_str();
    std::cout<<str1;
    

    Returns

    foobar