Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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();
like image 712
Gustavo V Avatar asked Apr 15 '26 21:04

Gustavo V


2 Answers

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();
like image 54
Bojan Hrnkas Avatar answered Apr 17 '26 10:04

Bojan Hrnkas


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.

like image 26
Luca Matteis Avatar answered Apr 17 '26 12:04

Luca Matteis



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!