本篇文章主要介紹寬字符串和標(biāo)準(zhǔn)字符串的互相轉(zhuǎn)換,對(duì)中文處理非常有用,標(biāo)準(zhǔn)字符串如果想輸出一個(gè)單漢字需要連續(xù)輸出兩個(gè)字節(jié),比較麻煩,下面給出一個(gè)完整的轉(zhuǎn)換程序,希望對(duì)看到本文章的人有幫助!![]() #include <iostream> struct auto_setlocate { string WstringToString(const wchar_t* wch) { string WstringToString(const wstring& wstr) { wstring StringToWstring(const char* ch) { wstring StringToWstring(const string& str) { int main() { // 函數(shù)string WstringToString(const wchar_t* wch) // 函數(shù)string WstringToString(const wstring& wstr) // 函數(shù)wstring StringToWstring(const char* ch) // 函數(shù)wstring StringToWstring(const string& str) return 0; 關(guān)于函數(shù)setlocale。 本函數(shù)用來配置地域的信息。參數(shù) category 有下列的選擇: LC_ALL 包括下面的全項(xiàng)選項(xiàng)都要。 LC_COLLATE 配置字符串比較,PHP 目前尚未實(shí)作出來本項(xiàng)。 LC_CTYPE 配置字符類別及轉(zhuǎn)換。例如全變大寫 strtoupper()。 LC_MONETARY 配置金融貨幣,PHP 目前尚未實(shí)作。 LC_NUMERIC 配置小數(shù)點(diǎn)后的位數(shù)。 LC_TIME 配置時(shí)間日期格式,與 strftime() 合用。 而參數(shù) locate 若是空字符串 "",則會(huì)使用系統(tǒng)環(huán)境變量的 locate 或是 LANG 的值。若 locate 為零,則不會(huì)改變地域化配置。返回新的地域,若系統(tǒng)尚未實(shí)作則返回 false。 另外,關(guān)于strlen,wcslen和lstrlen。 strlen() 返回ANSI字符串長(zhǎng)度; #include <iostream> int main() { cout<<wcslen(wct)<<endl; 關(guān)于wcstombs和mbstowcs函數(shù)請(qǐng)參考MSDN。 size_t wcstombs( char *mbstr, const wchar_t *wcstr, size_t count ); mbstr: The address of a sequence of multibyte characters wcstr: The address of a sequence of wide characters count: The maximum number of bytes that can be stored in the multibyte output string size_t mbstowcs( wchar_t *wcstr, const char *mbstr, size_t count ); wcstr: The address of a sequence of wide characters mbstr: The address of a sequence of multibyte characters count: The number of multibyte characters to convert |
|