2

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();
A. Levy
  • 29,056
  • 6
  • 39
  • 56
Gustavo V
  • 152
  • 1
  • 1
  • 4

2 Answers2

5

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();
Bojan Hrnkas
  • 1,587
  • 16
  • 22
  • 1
    _T converts a character or string to its Unicode counterpart, I think you meant CString("?") – 8bitwide Sep 27 '12 at 22:37
  • 3
    That is not true. _T converts the string to a proper character type, which depends on the project options. If you choose Unicode in project options, it converts string to const wchar*, otherwise it gives a const char* back. – Bojan Hrnkas Oct 03 '12 at 07:29
3

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.

Luca Matteis
  • 29,161
  • 19
  • 114
  • 169