c++文字(字串)格式轉換
阿新 • • 發佈:2018-12-20
//QString ->const wchar_t * const wchar_t * fileNameC = reinterpret_cast<const wchar_t *>([QString].utf16()); //const wchar_t *->char* char* nameCh = WcharToChar([const wchar_t *]); char* WcharToChar(const wchar_t* wc) { char* m_char = NULL; delete m_char; m_char = NULL; int len = WideCharToMultiByte(CP_ACP, 0, wc, wcslen(wc), NULL, 0, NULL, NULL); m_char = new char[len + 1]; WideCharToMultiByte(CP_ACP, 0, wc, wcslen(wc), m_char, len, NULL, NULL); m_char[len] = '\0'; return m_char; } //QString->string [QString].toStdString() //string->QString QString::fromStdString([string]) //string->const char * [string].c_str(); //const char *->char * const_cast<char*>([const char *]) //數字->string to_string(...)