std::string, std::wstring, wchar_t*, Platform::String^ 之间的相互转换

最近做WinRT的项目,涉及到Platform::String^  和 std::string之间的转换,总结一下:

(1)先给出源代码:

std::wstring stows(std::string s)
{
	std::wstring ws;
	ws.assign(s.begin(), s.end());
	return ws;
}

Platform::String^ stops(std::string s)
{
	return ref new Platform::String(stows(s).c_str());
}

std::string wstos(std::wstring ws)
{
	std::string s;
	s.assign(ws.begin(), ws.end());
	return s;
}

std::string pstos(Platform::String^ ps)
{
	return wstos(std::wstring(ps->Data()));
}

(2)画一个图更容易记忆:

  

 

 

posted @ 2014-01-09 11:03  大厨无盐煮  阅读(3291)  评论(0编辑  收藏  举报