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