Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save huihut/aa90bd3a202090e25b9a4792c80e6920 to your computer and use it in GitHub Desktop.
Save huihut/aa90bd3a202090e25b9a4792c80e6920 to your computer and use it in GitHub Desktop.
WinRT(C++/CX) type conversion between Platform::String^ and std::string
#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));
}
@escape-llc
Copy link

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment