本篇文章主要介紹寬字符串和標準字符串的互相轉(zhuǎn)換,對中文處理非常有用,標準字符串如果想輸出一個單漢字需要連續(xù)輸出兩個字節(jié),比較麻煩,下面給出一個完整的轉(zhuǎn)換程序,希望對看到本文章的人有幫助!![]() #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 包括下面的全項選項都要。 LC_COLLATE 配置字符串比較,PHP 目前尚未實作出來本項。 LC_CTYPE 配置字符類別及轉(zhuǎn)換。例如全變大寫 strtoupper()。 LC_MONETARY 配置金融貨幣,PHP 目前尚未實作。 LC_NUMERIC 配置小數(shù)點后的位數(shù)。 LC_TIME 配置時間日期格式,與 strftime() 合用。 而參數(shù) locate 若是空字符串 "",則會使用系統(tǒng)環(huán)境變量的 locate 或是 LANG 的值。若 locate 為零,則不會改變地域化配置。返回新的地域,若系統(tǒng)尚未實作則返回 false。 另外,關(guān)于strlen,wcslen和lstrlen。 strlen() 返回ANSI字符串長度; #include <iostream> int main() { cout<<wcslen(wct)<<endl; 關(guān)于wcstombs和mbstowcs函數(shù)請參考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 |
|
|
來自: just_person > 《C 》