共用方式為


basic_ios::narrow

尋找對等字元為指定的 char_type

char narrow(
    char_type _Char,
    char _Default = '\0'
) const;

參數

  • _Char
    要進行轉換的 char。

  • _Default
    您想要的傳回 char ,如果找不到對等用法。

傳回值

為指定的 char_type的對等 char 。

備註

成員函式會傳回 use_facet< ctype<E> >( getloc) ()。 narrow(_Char, _Default).

範例

// basic_ios_narrow.cpp
// compile with: /EHsc
#include <ios>
#include <iostream>
#include <wchar.h>

int main( ) 
{
   using namespace std;
   wchar_t *x = L"test";
   char y[10];
   cout << x[0] << endl;
   wcout << x << endl;
   y[0] = wcout.narrow( x[0] );
   cout << y[0] << endl;
}

Output

116
test
t

需求

標題: <ios>

命名空間: std

請參閱

參考

basic_ios 類別

iostream 程式設計

iostreams 慣例