-
June 23rd, 2021, 10:09 PM
#1
How to convert CString to wstring_view?
Hi,
I'm just starting, Can i convert CString to wstring_view like this?
CString s= L"abc";
wstring_view x{ (LPCTSTR)s };
Thanks you!
-
June 24th, 2021, 12:28 AM
#2
Re: How to convert CString to wstring_view?
To convert CString to std::wstring:
Code:
CString hi("Hi");
std::wstring hi2(hi);
And to go the other way, use c_str():
Code:
std::wstring hi(L"Hi");
CString hi2(hi.c_str());
Last edited by 2kaud; June 24th, 2021 at 03:14 AM.
Reason: Removed advertising link
-
June 24th, 2021, 01:40 AM
#3
Re: How to convert CString to wstring_view?
Originally Posted by Dang.D.Khanh
Hi,
I'm just starting, Can i convert CString to wstring_view like this?
CString s = L"abc";
wstring_view x{ (LPCTSTR)s };
Thanks you!
It depends upon what type of build you are using: UNICODE or MBCS.
It will work in UNICODE build, but NOT in MBCS.
for let it work in MBCS you could change it to
Code:
CStringW s= L"abc";
wstring_view x((LPCWSTR)s);
Victor Nijegorodov
-
June 24th, 2021, 03:34 PM
#4
Re: How to convert CString to wstring_view?
Hi,
Thank sir. now it worked.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|