Gustavo V
Gustavo V

Reputation: 152

How to concatenate multiple CString

All functions return CString, this is a MFC code and must compile in 32 & 64 bits.

Currently I'm using

CString sURI = GetURL();
sURI += GetMethod();
sURI += "?";
sURI += GetParameters();

Exists any manner to do the same like:

CString sURI = GetURL() + GetMethod() + "?" + GetParameters();

Upvotes: 2

Views: 34927

Answers (2)

Bojan Hrnkas
Bojan Hrnkas

Reputation: 1694

Problem is that "?" of type "const char*" is, and its + operator does not take right hand operand of type CString. You have to convert "?" to CString like this:

CString sURI = GetURL() + GetMethod() + _T("?") + GetParameters();

Upvotes: 6

Luca Matteis
Luca Matteis

Reputation: 29267

As long as all those functions return a CString object, then it should be fine to use the + operator for concatenation.

Otherwise use the CString _T(const char *) function to wrap your regular C strings and make them a CString.

Upvotes: 3

Related Questions