C++中的WCBOTE()函数

C++中的WcButter(函数)有助于转换宽字符 厕所 如果初始移位状态下的多字节字符等效为单字节,则转换为单字节。由于,该函数使用单字节编码,因此用于ASCII字符集中的字符。

null

语法:

int wctob (wint_t wc);

参数: 上述函数接受一个参数,如下所述:

  • 厕所: 这是wctob()函数接受的唯一参数,它是需要缩小/转换的宽字符。

    返回类型: 如果宽字符wc对应于初始状态下长度为单字节的多字节字符,则该函数返回宽字符wc的单字节表示形式。否则,它将返回EOF(文件结束)。

    以下程序说明了上述功能:

    项目1:

    // Program illustrating
    // wctob() function
    #include <bits/stdc++.h>
    // function implementing the wctob() function
    int fun()
    {
    int i, num;
    const wchar_t wc[] = L "priya lal" ;
    num = 0;
    for (i = 0; i < wcslen(wc); ++i)
    if (wctob(wc[i]) != EOF)
    ++num;
    // prints the numbers of characters
    // needed to be translated
    wprintf(L "wc has %d characters to be translated"
    "to single-byte characters." ,
    num);
    }
    // Driver Program
    int main()
    {
    fun();
    return 0;
    }

    
    

    输出:

    wc has 9 characters to be translatedto single-byte characters.
    

    项目2:

    // C++ program illustrating the wctob() function
    #include <bits/stdc++.h>
    // function implementing the wctob() function
    void fun( wchar_t wc)
    {
    int cn = wctob(wc);
    if (cn != EOF)
    printf ( "%#x translated to %#x" , wc, cn);
    else
    printf ( "%#x could not be translated" , wc);
    }
    // Driver Program
    int main( void )
    {
    char * utf_locale_present
    = setlocale (LC_ALL, "th_TH.utf8" );
    // prints the result of the function
    puts ( "In Thai UTF-8 locale:" );
    fun(L 'a' );
    fun(L '?' );
    }

    
    

    输出:

    In Thai UTF-8 locale:
    0x61 translated to 0x61
    0x3f translated to 0x3f
    

  • © 版权声明
    THE END
    喜欢就支持一下吧
    点赞8 分享