CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Jun 2021
    Posts
    51

    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!

  2. #2
    Join Date
    Jun 2021
    Posts
    10

    Thumbs up 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

  3. #3
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: How to convert CString to wstring_view?

    Quote Originally Posted by Dang.D.Khanh View Post
    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

  4. #4
    Join Date
    Jun 2021
    Posts
    51

    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
  •  





Click Here to Expand Forum to Full Width

Featured