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