Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All
Important This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here.


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

This method is potentially unsafe, as it relies on the caller to check that the passed values are correct. Consider using ctype::_Narrow_s instead.

char narrow(
   CharType _Ch, 
   char _Dfault
) const;
const CharType* narrow(
   const CharType* _First, 
   const CharType* _Last,
   char _Dfault, 
   char* _Dest
) const;



The character of type Chartype used by the locale to be converted.


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


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


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


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

The first member function returns the native character of type char that corresponds to the parameter character of type CharType _Dfault if not counterpart is defined.

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

The first member function returns do_narrow(_Ch, _Dfault). The second member function returns do_narrow (_First, _Last, _Dfault, _Dest). Only the basic source characters are guaranteed to have a unique inverse image CharType under narrow. For these basic source characters, the following invariant holds: narrow ( widenc ), 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];
   // Note:: ctype::narrow is potentially unsafe, consider
   // using ctype::_Narrow_s instead.
   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;


Xhello everyone

Header: <locale>


ctype Class

Other Resources

ctype Members

Community Additions

© 2015 Microsoft