function template
<locale>
std::isprint
template <class charT> bool isprint (charT c, const locale& loc);
Check if character is printable using locale
Checks whether c is a printable character using the ctype facet of locale loc, returning the same as if ctype::is is called as:
1
| use_facet < ctype<charT> > (loc).is (ctype_base::print, c)
|
This function template overloads the C function isprint (defined in <cctype>).
Parameters
- c
- Character to be checked.
- loc
- Locale to be used. It shall have a ctype facet.
The template argument charT is the character type.
Return Value
true
if indeed c is a printable character.
false
otherwise.
Example
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
| // isprint example (C++) #include <iostream> // std::cout #include <string> // std::string #include <locale> // std::locale, std::isprint int main () { std::locale loc; std::string str="first line \n second line \n"; for (std::string::size_type i=0; i<str.length(); ++i) { if (!std::isprint(str[i])) break; std::cout << str[i]; } return 0; }
|
Output:
Data races
Both loc and its ctype facet are accessed.
Exception safety
Strong guarantee: if an exception is thrown, there are no effects.
See also
- ctype
- Character type facet (class template)
- isprint (cctype)
- Check if character is printable (function)
- iscntrl
- Check if character is a control character using locale (function template)
- isspace
- Check if character is a white-space using locale (function template)
- isalnum
- Check if character is alphanumeric using locale (function template)