This documentation is archived and is not being maintained.

ctype::_Narrow_s 

Converts characters of type CharType used by a locale to the corresponding characters of type char in the native character set.


const CharType *_Narrow_s(
    const CharType *_First,
    const CharType *_Last,
    char _Dfault,
    char *_Dest,
    size_t _Dest_size
) const;

Parameters

_First

A pointer to the first character in the range of characters to be converted.

_Last

A pointer to the character immediately following the last character in the range of characters to be converted.

_Dfault

The default value to be assigned by the member function to characters of type CharType that do not have counterpart characters of type char.

_Dest

A const pointer to the first character of type char in the destination range that stores the converted range of characters.

_Dest_size

The size of _Dest in bytes.

This member function returns a pointer to the destination range of native characters converted from characters of type CharType.

This member function returns _Do_narrow_s(_First, _Last, _Dfault, _Dest, _Dest_size).

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

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

Output

Xhello everyone

Header: <locale>

Show: