xml 读取
TiXmlElement * elem = nodeElem->FirstChildElement();
std::string ss = elem->Value();
for (elem; elem != NULL; elem = elem->NextSiblingElement())
{
TiXmlAttribute *pAttr = elem->FirstAttribute();
std::string test = pAttr->Name();
pAttr->Value()
wchar_t* value = ConvertUtf8ToUnicode(pAttr->Value());
TiXmlElement * retElem = elem->FirstChildElement();
std::string tmp = retElem->Value();
std::string slope = retElem->GetText();
equipmentInfo info;
strcpy(info.m_name, UnicodeToAnsi(value));
info.m_slope = std::stof(slope);
equipInfo.push_back(info);
}
wchar_t* ConvertUtf8ToUnicode(const char* utf8)
{
if(!utf8)
{
wchar_t* buf = (wchar_t*)malloc(2);
memset(buf,0,2);
return buf;
}
int nLen = ::MultiByteToWideChar(CP_UTF8,MB_ERR_INVALID_CHARS,(LPCSTR)utf8,-1,NULL,0);
WCHAR * wszUNICODE = new WCHAR[nLen+1];
memset(wszUNICODE, 0, nLen * 2 + 2);
nLen = MultiByteToWideChar(CP_UTF8, 0, (LPCSTR)utf8, -1, wszUNICODE, nLen);
return wszUNICODE;
}
char* UnicodeToAnsi(const wchar_t* szStr)
{
int nLen = WideCharToMultiByte( CP_ACP, 0, szStr, -1, NULL, 0, NULL, NULL );
if (nLen == 0)
return NULL;
char* pResult = new char[nLen+1];
WideCharToMultiByte( CP_ACP, 0, szStr, -1, pResult, nLen, NULL, NULL );
return pResult;
}
wchar_t* AnsiToUnicode(const char* szStr)
{
int nLen = MultiByteToWideChar( CP_ACP, MB_PRECOMPOSED, szStr, -1, NULL, 0 );
if (nLen == 0)
return NULL;
wchar_t* pResult = new wchar_t[nLen+1];
MultiByteToWideChar( CP_ACP, MB_PRECOMPOSED, szStr, -1, pResult, nLen );
return pResult;
}