MFC CString Constructor action
CString Str1 = "ABC";
CString Str2 = Str1 + "123"; // Understandable
CString Str3 = "123" + Str1; // How does it work? Is there data overriding?
Does the last operation use CString '+' operator overloading, although Str1 is on the right of the '+'?
Thanks of answering.
c++ mfc c-strings
add a comment |
CString Str1 = "ABC";
CString Str2 = Str1 + "123"; // Understandable
CString Str3 = "123" + Str1; // How does it work? Is there data overriding?
Does the last operation use CString '+' operator overloading, although Str1 is on the right of the '+'?
Thanks of answering.
c++ mfc c-strings
add a comment |
CString Str1 = "ABC";
CString Str2 = Str1 + "123"; // Understandable
CString Str3 = "123" + Str1; // How does it work? Is there data overriding?
Does the last operation use CString '+' operator overloading, although Str1 is on the right of the '+'?
Thanks of answering.
c++ mfc c-strings
CString Str1 = "ABC";
CString Str2 = Str1 + "123"; // Understandable
CString Str3 = "123" + Str1; // How does it work? Is there data overriding?
Does the last operation use CString '+' operator overloading, although Str1 is on the right of the '+'?
Thanks of answering.
c++ mfc c-strings
c++ mfc c-strings
asked Nov 15 '18 at 6:41
SagiSagi
133
133
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
The MFC/ATL CStringT class template provides the following operator+ operators as free functions:
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);
The statement CString Str3 = "123" + Str1;
cannot use a class member, as there is no class object on the left-hand side of the +
expression, and no user-defined implicit conversion operator. It needs to invoke a free function, and uses the overload taking a PCXSTR argument.
Note, that this implies, that your project is set to use ANSI (MBCS) encoding. This is not generally desirable. Use Unicode instead, either by setting the appropriate preprocessor symbols (see Working with Strings for details), or by explicitly using the wide character versions (CStringW
) and prepending string literals with an L
(L"123"
).
add a comment |
CString Str3 = "123" + Str1;
Here you can see the various overloads of operator+
that CString
supports and one of them includes the above example.
Note: Concatenating two string literals like below is not supported for that would be equivalent to adding two pointers.
CString Str3 = "123" + "456"
2
CString
isn't Microsoft's version ofstd::string
. It is part of Microsoft's MFC. MFC'sCString
is completely unrelated tostd::string
.
– IInspectable
Nov 15 '18 at 8:42
I said, "seems to be". I did not know for sure. But I can update the answer to remove reference to std::string part because that is not really necessary I think.
– P.W
Nov 15 '18 at 8:44
That still links to outdated documentation, that's no longer correct.
– IInspectable
Nov 15 '18 at 8:52
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53313783%2fmfc-cstring-constructor-action%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
The MFC/ATL CStringT class template provides the following operator+ operators as free functions:
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);
The statement CString Str3 = "123" + Str1;
cannot use a class member, as there is no class object on the left-hand side of the +
expression, and no user-defined implicit conversion operator. It needs to invoke a free function, and uses the overload taking a PCXSTR argument.
Note, that this implies, that your project is set to use ANSI (MBCS) encoding. This is not generally desirable. Use Unicode instead, either by setting the appropriate preprocessor symbols (see Working with Strings for details), or by explicitly using the wide character versions (CStringW
) and prepending string literals with an L
(L"123"
).
add a comment |
The MFC/ATL CStringT class template provides the following operator+ operators as free functions:
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);
The statement CString Str3 = "123" + Str1;
cannot use a class member, as there is no class object on the left-hand side of the +
expression, and no user-defined implicit conversion operator. It needs to invoke a free function, and uses the overload taking a PCXSTR argument.
Note, that this implies, that your project is set to use ANSI (MBCS) encoding. This is not generally desirable. Use Unicode instead, either by setting the appropriate preprocessor symbols (see Working with Strings for details), or by explicitly using the wide character versions (CStringW
) and prepending string literals with an L
(L"123"
).
add a comment |
The MFC/ATL CStringT class template provides the following operator+ operators as free functions:
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);
The statement CString Str3 = "123" + Str1;
cannot use a class member, as there is no class object on the left-hand side of the +
expression, and no user-defined implicit conversion operator. It needs to invoke a free function, and uses the overload taking a PCXSTR argument.
Note, that this implies, that your project is set to use ANSI (MBCS) encoding. This is not generally desirable. Use Unicode instead, either by setting the appropriate preprocessor symbols (see Working with Strings for details), or by explicitly using the wide character versions (CStringW
) and prepending string literals with an L
(L"123"
).
The MFC/ATL CStringT class template provides the following operator+ operators as free functions:
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);
The statement CString Str3 = "123" + Str1;
cannot use a class member, as there is no class object on the left-hand side of the +
expression, and no user-defined implicit conversion operator. It needs to invoke a free function, and uses the overload taking a PCXSTR argument.
Note, that this implies, that your project is set to use ANSI (MBCS) encoding. This is not generally desirable. Use Unicode instead, either by setting the appropriate preprocessor symbols (see Working with Strings for details), or by explicitly using the wide character versions (CStringW
) and prepending string literals with an L
(L"123"
).
edited Nov 15 '18 at 9:11
answered Nov 15 '18 at 8:50
IInspectableIInspectable
26.4k64499
26.4k64499
add a comment |
add a comment |
CString Str3 = "123" + Str1;
Here you can see the various overloads of operator+
that CString
supports and one of them includes the above example.
Note: Concatenating two string literals like below is not supported for that would be equivalent to adding two pointers.
CString Str3 = "123" + "456"
2
CString
isn't Microsoft's version ofstd::string
. It is part of Microsoft's MFC. MFC'sCString
is completely unrelated tostd::string
.
– IInspectable
Nov 15 '18 at 8:42
I said, "seems to be". I did not know for sure. But I can update the answer to remove reference to std::string part because that is not really necessary I think.
– P.W
Nov 15 '18 at 8:44
That still links to outdated documentation, that's no longer correct.
– IInspectable
Nov 15 '18 at 8:52
add a comment |
CString Str3 = "123" + Str1;
Here you can see the various overloads of operator+
that CString
supports and one of them includes the above example.
Note: Concatenating two string literals like below is not supported for that would be equivalent to adding two pointers.
CString Str3 = "123" + "456"
2
CString
isn't Microsoft's version ofstd::string
. It is part of Microsoft's MFC. MFC'sCString
is completely unrelated tostd::string
.
– IInspectable
Nov 15 '18 at 8:42
I said, "seems to be". I did not know for sure. But I can update the answer to remove reference to std::string part because that is not really necessary I think.
– P.W
Nov 15 '18 at 8:44
That still links to outdated documentation, that's no longer correct.
– IInspectable
Nov 15 '18 at 8:52
add a comment |
CString Str3 = "123" + Str1;
Here you can see the various overloads of operator+
that CString
supports and one of them includes the above example.
Note: Concatenating two string literals like below is not supported for that would be equivalent to adding two pointers.
CString Str3 = "123" + "456"
CString Str3 = "123" + Str1;
Here you can see the various overloads of operator+
that CString
supports and one of them includes the above example.
Note: Concatenating two string literals like below is not supported for that would be equivalent to adding two pointers.
CString Str3 = "123" + "456"
edited Nov 15 '18 at 8:48
answered Nov 15 '18 at 6:55
P.WP.W
18k41657
18k41657
2
CString
isn't Microsoft's version ofstd::string
. It is part of Microsoft's MFC. MFC'sCString
is completely unrelated tostd::string
.
– IInspectable
Nov 15 '18 at 8:42
I said, "seems to be". I did not know for sure. But I can update the answer to remove reference to std::string part because that is not really necessary I think.
– P.W
Nov 15 '18 at 8:44
That still links to outdated documentation, that's no longer correct.
– IInspectable
Nov 15 '18 at 8:52
add a comment |
2
CString
isn't Microsoft's version ofstd::string
. It is part of Microsoft's MFC. MFC'sCString
is completely unrelated tostd::string
.
– IInspectable
Nov 15 '18 at 8:42
I said, "seems to be". I did not know for sure. But I can update the answer to remove reference to std::string part because that is not really necessary I think.
– P.W
Nov 15 '18 at 8:44
That still links to outdated documentation, that's no longer correct.
– IInspectable
Nov 15 '18 at 8:52
2
2
CString
isn't Microsoft's version of std::string
. It is part of Microsoft's MFC. MFC's CString
is completely unrelated to std::string
.– IInspectable
Nov 15 '18 at 8:42
CString
isn't Microsoft's version of std::string
. It is part of Microsoft's MFC. MFC's CString
is completely unrelated to std::string
.– IInspectable
Nov 15 '18 at 8:42
I said, "seems to be". I did not know for sure. But I can update the answer to remove reference to std::string part because that is not really necessary I think.
– P.W
Nov 15 '18 at 8:44
I said, "seems to be". I did not know for sure. But I can update the answer to remove reference to std::string part because that is not really necessary I think.
– P.W
Nov 15 '18 at 8:44
That still links to outdated documentation, that's no longer correct.
– IInspectable
Nov 15 '18 at 8:52
That still links to outdated documentation, that's no longer correct.
– IInspectable
Nov 15 '18 at 8:52
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53313783%2fmfc-cstring-constructor-action%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown