次の方法で共有


ctype::narrow

ネイティブな文字セットで型 char の対応する文字にロケールによって使用される型 CharType の文字を変換します。

char narrow(
    CharType ch, 
    char default = '\0'
) const;
const CharType* narrow(
    const CharType* first, 
    const CharType* last,
    char default, 
    char* dest
) const;

パラメーター

  • ch
    変換されるロケールによって使用される型 Chartype の文字。

  • default
    型 charの同等の文字がない型 CharType の文字にメンバー関数が割り当てられた既定値。

  • first
    変換される文字の範囲の最初の文字へのポインター。

  • last
    変換される文字範囲の最後の文字に続く文字へのポインター。

  • dest
    変換された文字の範囲を格納する先の範囲の型 char の最初の文字への const ポインター。

戻り値

一つ目のメンバー関数は、同じ型が定義されている場合 CharTypedefault のパラメーターの文字に対応する型 char のネイティブな文字を返します。

2 番目のメンバー関数は、型 CharTypeの文字から変換されたネイティブな文字の範囲へのポインターを返します。

解説

一つ目のメンバー関数は do_narrow (ch、default) を返します。2 番目のメンバー関数は do_narrow (first、last、default、dest) を返します。基本ソース文字だけ narrowの下に一意のオブジェクト CharType イメージがあることが保証されます。これらの基本ソースの文字では、次の保留: narrow ( widen ( c ), 0 ) == c.

使用例

// ctype_narrow.cpp
// compile with: /EHsc /W3
#include <locale>
#include <iostream>
using namespace std;

int main( )
{
   locale loc1 ( "english" );
   wchar_t *str1 = L"\x0392fhello everyone";
   char str2 [16];
   bool result1 = (use_facet<ctype<wchar_t> > ( loc1 ).narrow
      ( str1, str1 + wcslen(str1), 'X', &str2[0] ) != 0);  // C4996
   str2[wcslen(str1)] = '\0';
   wcout << str1 << endl;
   cout << &str2[0] << endl;
}
  

必要条件

ヘッダー: <locale>

名前空間: std

参照

関連項目

ctype Class