这个 btowc() 是C/C++中的一个内置函数,用于将字符转换为等效的宽字符。它是在 cwchar C++的头文件。
null
语法 :
wint_t btowc( int ch );
参数 :该函数接受一个强制参数 中国 它指定要转换为其宽字符的单字节字符。
返回值 : 如果ch是有效的单字节字符,则函数返回ch的宽字符表示形式。如果ch是 EOF , 韦奥夫 被退回。
下面的程序说明了上述功能。
方案1 :
// Program to illustrate // btowc() function #include <cstring> #include <cwchar> #include <iostream> using namespace std; int main() { char str[] = "Geeksforxf4xdgeeks" ; wchar_t wc; int count = 0; for ( int i = 0; i < strlen (str); i++) { wc = btowc(str[i]); if (wc != WEOF) count++; } cout << count << " out of " << strlen (str) << " Characters were successfully widened" ; return 0; } |
输出:
14 out of 15 Characters were successfully widened
方案2 :
// Program to illustrate // btowc() function #include <cstring> #include <cwchar> #include <iostream> using namespace std; int main() { char str[] = "Ishwarxa1xcGupta" ; wchar_t wc; int count = 0; for ( int i = 0; i < strlen (str); i++) { wc = btowc(str[i]); if (wc != WEOF) count++; } cout << count << " out of " << strlen (str) << " Characters were successfully widened" ; return 0; } |
输出:
12 out of 13 Characters were successfully widened
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END