Namespaces
Variants
Views
Actions

std::isprint(std::locale)

From cppreference.com
< cpp‎ | locale
Revision as of 10:30, 3 October 2023 by Andreas Krug (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
 
 
 
Defined in header <locale>
template< class CharT >
bool isprint( CharT ch, const locale& loc );

Checks if the given character is classified as a printable character (including space) by the given locale's std::ctype facet.

Contents

[edit] Parameters

ch - character
loc - locale

[edit] Return value

Returns true if the character is classified as printable, false otherwise.

[edit] Possible implementation

template<class CharT>
bool isprint(CharT ch, const std::locale& loc)
{
    return std::use_facet<std::ctype<CharT>>(loc).is(std::ctype_base::print, ch);
}

[edit] Example

Demonstrates the use of isprint() with different locales (OS-specific).

#include <iostream>
#include <locale>
 
int main()
{
    const wchar_t c = L'\u2122'; // trademark sign
 
    std::locale loc1("C");
    std::cout << "isprint('™', C locale) returned "
              << std::boolalpha << std::isprint(c, loc1) << '\n';
 
    std::locale loc2("en_US.UTF-8");
    std::cout << "isprint('™', Unicode locale) returned "
              << std::boolalpha << std::isprint(c, loc2) << '\n';
}

Possible output:

isprint('™', C locale) returned false
isprint('™', Unicode locale) returned true

[edit] See also

checks if a character is a printing character
(function) [edit]
checks if a wide character is a printing character
(function) [edit]