int mbtowc(whcar_t *pwc, const char *str, size_t n)

C 标准库 - <stdlib.h> C 标准库 - <stdlib.h>

描述

C 库函数 int mbtowc(whcar_t *pwc, const char *str, size_t n) 把一个多字节序列转换为一个宽字符。

声明

下面是 mbtowc() 函数的声明。

int mbtowc(whcar_t *pwc, const char *str, size_t n)

参数

返回值

实例

下面的实例演示了 mbtowc() 函数的用法。

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main()
{
   char *str = "这里是 example.com";
   wchar_t mb[100];
   int len;
   
   len = mblen(NULL, MB_CUR_MAX); 

   mbtowc(mb, str, len*strlen(str) );
   
   wprintf(L"%ls \n", mb );   
   
   return(0);
}

让我们编译并运行上面的程序,这将产生以下结果,因为它要以多字节形式输出结果,这是一种二进制输出。

???

C 标准库 - <stdlib.h> C 标准库 - <stdlib.h>