std::ctype<CharT>::narrow,do_narrow (3) - Linux Manuals
std::ctype<CharT>::narrow,do_narrow: std::ctype<CharT>::narrow,do_narrow
NAME
std::ctype<CharT>::narrow,do_narrow - std::ctype<CharT>::narrow,do_narrow
Synopsis
Defined in header <locale>
public: (1)
char narrow( CharT c, char dflt ) const;
public:
const CharT* narrow( const CharT* beg, const CharT* end, (2)
char dflt, char* dst ) const;
protected: (3)
virtual char do_narrow( CharT c, char dflt ) const;
protected:
virtual const CharT* do_narrow( const CharT* beg, const CharT* end, (4)
char dflt, char* dst ) const;
1,2) Public member function, calls the protected virtual member function do_narrow of the most derived class.
3) Converts the (possibly wide) character c to multibyte representation if the character can be represented with a single byte (for example, ASCII characters in UTF-8 encoding are single bytes). Returns dflt if such conversion does not exist.
4) For every character in the character array [beg, end), writes narrowed characters (or dflt whenever narrowing fails) to the successive locations in the character array pointed to by dst.
Narrowing is always successful and is always reversible (by calling widen()) for all characters from the basic source character set (latin letters, digits, and punctuations required to write a C++ program)
Narrowing, if successful, preserves all character classification categories known to is().
Narrowing of any digit character guarantees that if the result is subtracted from the character literal '0', the difference equals the digit value of the original character.
Parameters
c - character to convert
dflt - default value to produce if the conversion fails
beg - pointer to the first character in an array of characters to convert
end - one past the end pointer for the array of characters to convert
dst - pointer to the first element of the array of char to fill
Return value
1,3) narrowed character or dflt if narrowing fails
2,4) end
Example
// Run this code
Output:
See also
widen (public member function)
narrow (public member function of std::basic_ios<CharT,Traits>)
wctob (function)