C11 宽字节转为多字节实现

BOOL WStringToString(const std::wstring &wstr,std::string &str)
{   
	typedef std::codecvt convert_facet;
	std::locale mylocale;
	const convert_facet& myfacet = std::use_facet(mylocale);
	size_t length_ = wstr.length();
	std::unique_ptr pstr(new char[length_+1]);
	std::mbstate_t mbs = std::mbstate_t();
	const wchar_t* pwc;
	char* pc;
	convert_facet::result myresult = myfacet.out(mbs,wstr.c_str(),wstr.c_str()+length_+1,pwc,pstr.get(),pstr.get()+length_+1,pc);
	if (myresult != convert_facet::ok)
		return FALSE;
	str = pstr.get();
	return TRUE;
}

你可能感兴趣的:(C11)