名前空間
変種
操作

std::wcsrtombs

提供: 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
wctomb
wcstombs
wctob
wcrtomb
wcsrtombs
c16rtomb(C++11)
c32rtomb(C++11)
mbrlen
タイプ
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 <cwchar>
std::size_t wcsrtombs( char* dst,

                       const wchar_t** src,
                       std::size_t len,

                       std::mbstate_t* ps );
最初の要素*srcによって記述変換状態で始まるその狭いマルチバイト表現に*psによって指された配列のワイド文字のシーケンスに変換します。 dstがnullでない場合、変換された文字はdstが指すchar型の配列の連続する要素に格納されています。 lenバイト以上は、コピー先の配列に書き込まれません.
Original:
Converts a sequence of wide characters from the array whose first element is pointed to by *src to its narrow multibyte representation that begins in the conversion state described by *ps. If dst is not null, converted characters are stored in the successive elements of the char array pointed to by dst. No more than len bytes are written to the destination array.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
各文字はstd::wcrtombへの呼び出しと同じように変換されます。次の場合、変換は終了します
Original:
Each character is converted as if by a call to std::wcrtomb. The conversion stops if:
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
  • ヌル文字が変換されて格納されていました。 srcに設定されているNULL*ps初期シフト状態を表します.
    Original:
    The null character was converted and stored. src is set to NULL and *ps represents 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.
  • wchar_tは、現在のCロケールで有効な文字に対応していないことが分かった。 srcはない最初のワイド文字を指すように設定されています.
    Original:
    A wchar_t was found that does not correspond to a valid character in the current C locale. src is set to point at the first unconverted wide character.
    The text has been machine-translated via Google Translate.
    You can help to correct and verify the translation. Click here for instructions.
  • 格納する次のマルチバイト文字がlenを超えてしまいます。 srcはない最初のワイド文字を指すように設定されています。 dst==NULL場合、この条件がチェックされていません.
    Original:
    the next multibyte character to be stored would exceed len. src is set to point at the first unconverted wide character. This condition is not checked if dst==NULL.
    The text has been machine-translated via Google Translate.
    You can help to correct and verify the translation. Click here for instructions.

目次

[編集] パラメータ

dst -
マルチバイト文字が格納される狭い文字配列へのポインタ
Original:
pointer to narrow character array where the multibyte characters will be stored
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
src -
nullで終了するワイド文字列の最初の要素へのポインタへのポインタ
Original:
pointer to pointer to the first element of a null-terminated wide string
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
len -
dstが指す配列内の利用可能なバイト数
Original:
number of bytes available in the array pointed to by dst
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
ps -
変換状態オブジェクトへのポインタ
Original:
pointer to the conversion state object
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

[編集] 値を返します

成功した場合、最初の要素が'\0'によって指された文字配列に書き込まれたバイト数を(任意のシフトシーケンスを含むが、終端dstを除く)を返します。 dst==NULLた場合、書き込まれたであろうバイト数を返します。.
Original:
On success, returns the number of bytes (including any shift sequences, but excluding the terminating '\0') written to the character array whose first element is pointed to by dst. If dst==NULL, returns the number of bytes that would have been written.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
変換エラー(不正なワイド文字が検出された場合)に、static_cast<std::size_t>(-1)の店舗EILSEQerrnoを返し、指定されていない状態で*psを残し.
Original:
On conversion error (if invalid wide character was encountered), returns static_cast<std::size_t>(-1), stores EILSEQ in errno, and leaves *ps in unspecified state.
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 <vector>
#include <clocale>
#include <string>
#include <cwchar>
 
void print_wide(const wchar_t* wstr)
{
    std::mbstate_t state = std::mbstate_t();
    int len = 1 + std::wcsrtombs(NULL, &wstr, 0, &state);
    std::vector<char> mbstr(len);
    std::wcsrtombs(&mbstr[0], &wstr, mbstr.size(), &state);
    std::cout << "multibyte string: " << &mbstr[0] << '\n'
              << "Length, including '\\0': " << mbstr.size() << '\n';
}
 
int main()
{
    std::setlocale(LC_ALL, "en_US.utf8");
    // UTF-8 narrow multibyte encoding
    const wchar_t* wstr = L"z\u00df\u6c34\U0001d10b"; // or L"zß水𝄋"
    print_wide(wstr);
}

Output:

multibyte string: zß水𝄋
Length, including '\0': 11

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

そのマルチバイト表現、所定の状態にワイド文字に変換します
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]
ワイド文字列へのナローマルチバイト文字列、与えられた状態に変換します
Original:
converts a narrow multibyte character string to wide string, 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 wcsrtombs