名前空間
変種
操作

std::wctomb

提供: cppreference.com
< cpp‎ | string‎ | multibyte

 
 
ストリングスライブラリ
NULLで終わる文字列
Original:
Null-terminated strings
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
バイト文字列
文字列をマルチバイト
ワイド文字列
クラス
Original:
Classes
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
basic_string
char_traits
 
NULLで終わるマルチバイト文字列
マルチバイト/ワイドコンバージョン
Original:
Wide/multibyte conversions
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
mbsinit
タイプ
Original:
Types
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
mbstate_t
 
Defined in header <cstdlib>
int wctomb( char *s, wchar_t wc );
エンコードや店舗最初の要素wcによって指されるchar型の配列で、それを(任意のシフトシーケンスを含む)をマルチバイトにワイド文字sに変換します。 MB_CUR_MAX文字以上は保存されません.
Original:
Converts a wide character wc to multibyte encoding and stores it (including any shift sequences) in the char array whose first element is pointed to by s. No more than MB_CUR_MAX characters are stored.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
wcがヌル文字である場合、NULLバイトが、sに書き込ま初期シフト状態を回復させるために必要なシフトシーケンスによって先行さ.
Original:
If wc is the null character, the null byte is written to s, preceded by any shift sequences necessary to restore the initial shift state.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
sがNULLポインタの場合、リセットされ、グローバル変換状態で、シフトシーケンスが使用されているかどうか判断した場合には.
Original:
If s is a null pointer, resets the global conversion state and determines whether shift sequences are used.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

目次

[編集] パラメータ

s -
出力用の文字配列へのポインタ
Original:
pointer to the character array for output
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
wc -
変換するワイド文字
Original:
wide character to convert
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

[編集] 値を返します

sがNULLポインタでない場合は、のマルチバイト表現に含まれるバイト数を返しますwcまたは-1場合wc有効な文字ではありません.
Original:
If s is not a null pointer, returns the number of bytes that are contained in the multibyte representation of wc or -1 if wc is not a valid character.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
sがNULLポインターである場合、現在のマルチバイトエンコーディングがある場合、リセットは現在のマルチバイトエンコーディングが状態に依存していない場合、初期シフト状態を返し0を表すために、その内部の変換状態は、非ゼロ値(シフトシーケンスを使用しません)状態依存(シフトシーケンスを使用しています).
Original:
If s is a null pointer, resets its internal conversion state to represent the initial shift state and returns 0 if the current multibyte encoding is not state-dependent (does not use shift sequences) or a non-zero value if the current multibyte encoding is state-dependent (uses shift sequences).
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

[編集] ノート

wctombアップデート内部グローバル変換状態(これだけ機能することが知られているタイプstd::mbstate_tの静的オブジェクト)への各呼び出し。マルチバイトエンコーディングがシフト状態が使用されている場合、この関数はリエントラントではありません。どのような場合では、複数のスレッドが同期化されずにwctombを呼び出すべきではありません:std::wcrtombを代わりに使用することができ.
Original:
Each call to wctomb updates the internal global conversion state (a static object of type std::mbstate_t, only known to this function). If the multibyte encoding uses shift states, this function is not reentrant. In any case, multiple threads should not call wctomb without synchronization: std::wcrtomb may be used instead.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

[編集]

#include <iostream>
#include <clocale>
#include <string>
#include <cstdlib>
 
void print_wide(const std::wstring& wstr)
{
    bool shifts = std::wctomb(NULL, 0); // reset the conversion state
    std::cout << "shift sequences " << (shifts ? "are" : "not" ) << " used\n";
    for (wchar_t wc : wstr) {
        std::string mb(MB_CUR_MAX, '\0');
        int ret = std::wctomb(&mb[0], wc);
        std::cout << "multibyte char " << mb << " is " << ret << " bytes\n";
    }
}
 
int main()
{
    std::setlocale(LC_ALL, "en_US.utf8");
    // UTF-8 narrow multibyte encoding
    std::wstring wstr = L"z\u00df\u6c34\U0001d10b"; // or L"zß水𝄋"
    print_wide(wstr);
}

Output:

shift sequences not used
multibyte char z is 1 bytes
multibyte char ß is 2 bytes
multibyte char 水 is 3 bytes
multibyte char 𝄋 is 4 bytes

[編集] も参照してください

ワイド文字に次のマルチバイト文字に変換します
Original:
converts the next multibyte character to wide character
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(関数) [edit]
そのマルチバイト表現、所定の状態にワイド文字に変換します
Original:
converts a wide character to its multibyte representation, given state
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(関数) [edit]
[仮想]
そのようなファイルに書き込むときのように、internTからexternTに文字列を変換します
Original:
converts a string from internT to externT, such as when writing to file
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(仮想protectedメンバ関数of std::codecvt) [edit]
C documentation for wctomb