Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/google-maps/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ MFC CString构造函数操作_C++_Mfc_C Strings - Fatal编程技术网

C++ MFC CString构造函数操作

C++ MFC CString构造函数操作,c++,mfc,c-strings,C++,Mfc,C Strings,最后一个操作是否使用CString“+”运算符重载,尽管Str1位于“+”的右侧? 谢谢你的回答 CString Str1 = "ABC"; CString Str2 = Str1 + "123"; // Understandable CString Str3 = "123" + Str1; // How does it work? Is there data overriding? 您可以看到CString支持的operator+的各种重载,其中一个包括上述示例 注意:不支持像下面这样连接两

最后一个操作是否使用CString“+”运算符重载,尽管Str1位于“+”的右侧? 谢谢你的回答

CString Str1 = "ABC";
CString Str2 = Str1 + "123"; // Understandable
CString Str3 = "123" + Str1; // How does it work? Is there data overriding?
您可以看到
CString
支持的
operator+
的各种重载,其中一个包括上述示例

注意:不支持像下面这样连接两个字符串文本,因为这相当于添加两个指针

CString Str3 = "123" + Str1;
MFC/ATL类模板提供以下运算符作为自由函数:

语句
CString Str3=“123”+Str1不能使用类成员,因为
+
表达式的左侧没有类对象,也没有用户定义的隐式转换运算符。它需要调用一个自由函数,并使用重载获取参数


请注意,这意味着您的项目设置为使用ANSI(MBCS)编码。这通常是不可取的。使用Unicode,或者通过设置适当的预处理器符号(有关详细信息,请参阅),或者通过显式使用宽字符版本(
CStringW
)并使用
L
L“123”
)预加字符串文字(
L“123”
)。

CString
不是Microsoft版本的
std::string
。它是微软MFC的一部分。MFC的
CString
std::string
完全无关。我说,“似乎是”。我不确定。但我可以更新答案以删除对std::string部分的引用,因为我认为这并不是真的必要。它仍然链接到过时的文档,这不再正确。接受建议的答案的原因是什么,它既不回答您的问题,也不链接到正确的文档?
CString Str3 = "123" + "456"
friend CStringT operator+(const CStringT& str1, const CStringT& str2);
friend CStringT operator+(const CStringT& str1, PCXSTR psz2);
friend CStringT operator+(PCXSTR psz1, const CStringT& str2,);
friend CStringT operator+(char ch1, const CStringT& str2,);
friend CStringT operator+(const CStringT& str1, char ch2);
friend CStringT operator+(const CStringT& str1, wchar_t ch2);
friend CStringT operator+(wchar_t ch1, const CStringT& str2);