Last active
April 13, 2022 15:47
-
-
Save huihut/aa90bd3a202090e25b9a4792c80e6920 to your computer and use it in GitHub Desktop.
WinRT(C++/CX) type conversion between Platform::String^ and std::string
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <string> | |
std::string Managed_Str_To_Std_Str(Platform::String^ ms) | |
{ | |
std::wstring w_str(ms->Begin()); | |
return std::string(w_str.begin(), w_str.end()); | |
} | |
Platform::String^ Std_Str_To_Managed_Str(const std::string & input) | |
{ | |
std::wstring w_str = std::wstring(input.begin(), input.end()); | |
const wchar_t* w_chars = w_str.c_str(); | |
return (ref new Platform::String(w_chars)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
line 6 (return std::string) generates this error message now
see reference to function template instantiation 'std::basic_string<char,std::char_traits,std::allocator>::basic_string<std::_String_iterator<std::_String_val<std::_Simple_types<_Elem>>>,0>(_Iter,_Iter,const _Alloc &)' being compiled
with
[
_Elem=wchar_t,
_Iter=std::_String_iterator<std::_String_val<std::_Simple_types<wchar_t>>>,
_Alloc=std::allocator
]
can you explain why this error message?