C++ 中的wctrans() 函數返回對應於轉換的 wctrans_t 類型的值。
wctrans() 函數在<cwctype> 頭文件中定義。
wctrans()原型
wctrans_t wctrans(const char* str);
wctrans() 函數將 C 字符串作為其參數並返回用於映射寬字符的 wctrans_t 類型的值。
參數:
str
:指定所需轉換的 C 字符串。
返回:
- wctrans() 函數返回一個 wctrans_t 對象,該對象可與 towctrans() 一起用於映射寬字符。
- 如果
str
不提供當前 C 語言環境支持的映射,則返回零。
示例:wctrans() 函數如何工作?
#include <cwctype>
#include <iostream>
#include <cwchar>
#include <clocale>
using namespace std;
int main()
{
setlocale(LC_ALL, "en_US.UTF-8");
wchar_t str[] = L"Ŝŵitĉhiňģ Ćăse";
wcout << L"Before transformation" << endl;
wcout << str << endl;
for(int i=0; i<wcslen(str); i++)
{
if (iswctype(str[i], wctype("lower")))
str[i] = towctrans(str[i], wctrans("toupper"));
else if (iswctype(str[i], wctype("upper")))
str[i] = towctrans(str[i], wctrans("tolower"));
}
wcout << L"After transformation" << endl;
wcout << str << endl;
return 0;
}
運行程序時,輸出將是:
Before transformation Ŝŵitĉhiňģ Ćăse After transformation ŝŴITĈHIŇĢ ćĂSE
相關用法
- C++ wctrans()用法及代碼示例
- C++ wctob()用法及代碼示例
- C++ wctomb()用法及代碼示例
- C++ wctype()用法及代碼示例
- C++ wcstold()用法及代碼示例
- C++ wcerr用法及代碼示例
- C++ wcsftime()用法及代碼示例
- C++ wcstod()用法及代碼示例
- C++ wcscspn()用法及代碼示例
- C++ wcsncmp()用法及代碼示例
- C++ wcin用法及代碼示例
- C++ wcstok()用法及代碼示例
- C++ wcsstr()用法及代碼示例
- C++ wcsrchr()用法及代碼示例
- C++ wcsncpy()用法及代碼示例
- C++ wcslen()用法及代碼示例
- C++ wcsspn()用法及代碼示例
- C++ wclog用法及代碼示例
- C++ wcschr()用法及代碼示例
- C++ wcstof()用法及代碼示例
注:本文由純淨天空篩選整理自 C++ wctrans()。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。