C/C++语言中的c32rtomb()函数?
在C ++语言中,我们可以使用 32 位字符表示。c32rtomb() 函数用于将 32 位字符表示转换成窄的、多字节字符表示。我们可以在 uchar.h 头文件中找到此函数。
此函数接受三个参数。它们是:
- 存储多字节字符的字符串
- 要转换的 32 位字符
- 类型为 mbstate_t 对象的指针。该指针用于解释多字节字符串。
此函数返回写入字符数组的字节数,如果成功则返回 -1。让我们看一个示例以更好地理解。
示例
#include <iostream>
#include <uchar.h>
#include <wchar.h>
using namespace std;
int main() {
const char32_t myStr[] = U"Hello World";
char dest[50];
mbstate_t p{};
size_t length;
int j = 0;
while (myStr[j]) {
length = c32rtomb(dest, myStr[j], &p); //get length from c32rtomb() method
if ((length == 0) || (length > 50))
break;
for (int i = 0; i < length; ++i)
cout << dest[i];
j++;
}
}输出
Hello World
广告
数据结构
网络技术
关系数据库管理系统
操作系统
Java
iOS
HTML
CSS
Android
Python
C语言编程
C++
C#
MongoDB
MySQL
Javascript
PHP