How to concatenate multiple CString

元气小坏坏 提交于 2019-12-02 05:38:00

问题


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();

回答1:


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();



回答2:


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.



来源:https://stackoverflow.com/questions/3159194/how-to-concatenate-multiple-cstring

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!