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