Bagikan melalui


Fungsi <locale>

has_facet
isalnum
isalpha
iscntrl
isdigit
isgraph
islower
isprint
ispunct
isspace
isupper
isxdigit
tolower
toupper
use_facet

has_facet

Menguji apakah faset tertentu disimpan dalam lokal tertentu.

template <class Facet>
bool has_facet(const locale& Loc);

Parameter

Loc
Lokal yang akan diuji untuk kehadiran faset.

Tampilkan Nilai

true jika lokal memiliki faset yang diuji; false jika tidak.

Keterangan

Fungsi templat berguna untuk memeriksa apakah faset nonmandatori tercantum dalam lokal sebelumnya use_facet dipanggil untuk menghindari pengecualian yang akan dilemparkan jika tidak ada.

Contoh

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

int main( )
{
   locale loc ( "German_Germany" );
   bool result = has_facet <ctype<char> > ( loc );
   cout << result << endl;
}
1

isalnum

Menguji apakah elemen dalam lokal adalah karakter alfabet atau numerik.

template <class CharType>
bool isalnum(CharType Ch, const locale& Loc)

Parameter

Ch
Elemen alfanumerik yang akan diuji.

Loc
Lokal yang berisi elemen alfanumerik yang akan diuji.

Tampilkan Nilai

true jika elemen yang diuji adalah alfanumerik; false jika tidak.

Contoh

// locale_isalnum.cpp
// compile with: /EHsc
#include <locale>
#include <iostream>

using namespace std;

int main( )
{
   locale loc ( "German_Germany" );
   bool result1 = isalnum ( 'L', loc);
   bool result2 = isalnum ( '@', loc);
   bool result3 = isalnum ( '3', loc);

   if ( result1 )
      cout << "The character 'L' in the locale is "
           << "alphanumeric." << endl;
   else
      cout << "The character 'L' in the locale is "
           << " not alphanumeric." << endl;

   if ( result2 )
      cout << "The character '@' in the locale is "
           << "alphanumeric." << endl;
   else
      cout << "The character '@' in the locale is "
           << " not alphanumeric." << endl;

   if ( result3 )
      cout << "The character '3' in the locale is "
           << "alphanumeric." << endl;
   else
      cout << "The character '3' in the locale is "
           << " not alphanumeric." << endl;
}
The character 'L' in the locale is alphanumeric.
The character '@' in the locale is  not alphanumeric.
The character '3' in the locale is alphanumeric.

isalpha

Menguji apakah elemen dalam lokal adalah karakter alfabet.

template <class CharType>
bool isalpha(CharType Ch, const locale& Loc)

Parameter

Ch
Elemen yang akan diuji.

Loc
Lokal yang berisi elemen alfabet yang akan diuji.

Tampilkan Nilai

true jika elemen yang diuji adalah alfabet; false jika tidak.

Keterangan

Fungsi templat mengembalikan use_facet<ctype<CharType>>( ). Loc is( ctype<CharType>:: alpha, ). Ch

Contoh

// locale_isalpha.cpp
// compile with: /EHsc
#include <locale>
#include <iostream>

using namespace std;

int main( )
{
   locale loc ( "German_Germany" );
   bool result1 = isalpha ( 'L', loc);
   bool result2 = isalpha ( '@', loc);
   bool result3 = isalpha ( '3', loc);

   if ( result1 )
      cout << "The character 'L' in the locale is "
           << "alphabetic." << endl;
   else
      cout << "The character 'L' in the locale is "
           << " not alphabetic." << endl;

   if ( result2 )
      cout << "The character '@' in the locale is "
           << "alphabetic." << endl;
   else
      cout << "The character '@' in the locale is "
           << " not alphabetic." << endl;

   if ( result3 )
      cout << "The character '3' in the locale is "
           << "alphabetic." << endl;
   else
      cout << "The character '3' in the locale is "
           << " not alphabetic." << endl;
}

iscntrl

Menguji apakah elemen dalam lokal adalah karakter kontrol.

template <class CharType>
bool iscntrl(CharType Ch, const locale& Loc)

Parameter

Ch
Elemen yang akan diuji.

Loc
Lokal yang berisi elemen yang akan diuji.

Tampilkan Nilai

true jika elemen yang diuji adalah karakter kontrol; false jika tidak.

Keterangan

Fungsi templat mengembalikan use_facet<ctype<CharType>>( ). Loc is( ctype<CharType>:: cntrl, ). Ch

Contoh

// locale_iscntrl.cpp
// compile with: /EHsc
#include <locale>
#include <iostream>

using namespace std;

int main( )
{
   locale loc ( "German_Germany" );
   bool result1 = iscntrl ( 'L', loc );
   bool result2 = iscntrl ( '\n', loc );
   bool result3 = iscntrl ( '\t', loc );

   if ( result1 )
      cout << "The character 'L' in the locale is "
           << "a control character." << endl;
   else
      cout << "The character 'L' in the locale is "
           << " not a control character." << endl;

   if ( result2 )
      cout << "The character-set 'backslash-n' in the locale\n is "
           << "a control character." << endl;
   else
      cout << "The character-set 'backslash-n' in the locale\n is "
           << " not a control character." << endl;

   if ( result3 )
      cout << "The character-set 'backslash-t' in the locale\n is "
           << "a control character." << endl;
   else
      cout << "The character-set 'backslash-n' in the locale \n is "
           << " not a control character." << endl;
}

isdigit

Menguji apakah elemen dalam lokal adalah karakter numerik.

template <class CharType>
bool isdigit(CharType Ch, const locale& Loc)

Parameter

Ch
Elemen yang akan diuji.

Loc
Lokal yang berisi elemen yang akan diuji.

Tampilkan Nilai

true jika elemen yang diuji adalah karakter numerik; false jika tidak.

Keterangan

Fungsi templat mengembalikan use_facet<ctype<CharType>>( ). Loc is( ctype<CharType>:: digit, ). Ch

Contoh

// locale_is_digit.cpp
// compile with: /EHsc
#include <locale>
#include <iostream>

using namespace std;

int main( )
{
   locale loc ( "German_Germany" );
   bool result1 = isdigit ( 'L', loc );
   bool result2 = isdigit ( '@', loc );
   bool result3 = isdigit ( '3', loc );

   if ( result1 )
      cout << "The character 'L' in the locale is "
           << "a numeric character." << endl;
   else
      cout << "The character 'L' in the locale is "
           << " not a numeric character." << endl;

   if ( result2 )
      cout << "The character '@' in the locale is "
           << "a numeric character." << endl;
   else
      cout << "The character '@' in the locale is "
           << " not a numeric character." << endl;

   if ( result3 )
      cout << "The character '3' in the locale is "
           << "a numeric character." << endl;
   else
      cout << "The character '3' in the locale is "
           << " not a numeric character." << endl;
}

isgraph

Menguji apakah elemen dalam lokal adalah karakter alfanumerik atau tanda baca.

template <class CharType>
bool isgraph(CharType Ch, const locale& Loc)

Parameter

Ch
Elemen yang akan diuji.

Loc
Lokal yang berisi elemen yang akan diuji.

Tampilkan Nilai

true jika elemen yang diuji adalah karakter alfanumerik atau tanda baca; false jika tidak.

Keterangan

Fungsi templat mengembalikan use_facet<ctype<CharType>>( ). Loc is( ctype<CharType>:: graph, ). Ch

Contoh

// locale_is_graph.cpp
// compile with: /EHsc
#include <locale>
#include <iostream>

using namespace std;

int main( )
{
   locale loc ( "German_Germany" );
   bool result1 = isgraph ( 'L', loc );
   bool result2 = isgraph ( '\t', loc );
   bool result3 = isgraph ( '.', loc );

   if ( result1 )
      cout << "The character 'L' in the locale is\n "
           << "an alphanumeric or punctuation character." << endl;
   else
      cout << "The character 'L' in the locale is\n "
           << " not an alphanumeric or punctuation character." << endl;

   if ( result2 )
      cout << "The character 'backslash-t' in the locale is\n "
           << "an alphanumeric or punctuation character." << endl;
   else
      cout << "The character 'backslash-t' in the locale is\n "
           << "not an alphanumeric or punctuation character." << endl;

   if ( result3 )
      cout << "The character '.' in the locale is\n "
           << "an alphanumeric or punctuation character." << endl;
   else
      cout << "The character '.' in the locale is\n "
           << " not an alphanumeric or punctuation character." << endl;
}

islower

Menguji apakah elemen dalam lokal lebih rendah huruf besar/kecil.

template <class CharType>
bool islower(CharType Ch, const locale& Loc)

Parameter

Ch
Elemen yang akan diuji.

Loc
Lokal yang berisi elemen yang akan diuji.

Tampilkan Nilai

true jika elemen yang diuji adalah karakter huruf kecil; false jika tidak.

Keterangan

Fungsi templat mengembalikan use_facet<ctype<CharType>>( ). Loc is( ctype<CharType>:: lower, ). Ch

Contoh

// locale_islower.cpp
// compile with: /EHsc
#include <locale>
#include <iostream>

using namespace std;

int main( )
{
   locale loc ( "German_Germany" );
   bool result1 = islower ( 'L', loc );
   bool result2 = islower ( 'n', loc );
   bool result3 = islower ( '3', loc );

   if ( result1 )
      cout << "The character 'L' in the locale is "
           << "a lowercase character." << endl;
   else
      cout << "The character 'L' in the locale is "
           << " not a lowercase character." << endl;

   if ( result2 )
      cout << "The character 'n' in the locale is "
           << "a lowercase character." << endl;
   else
      cout << "The character 'n' in the locale is "
           << " not a lowercase character." << endl;

   if ( result3 )
      cout << "The character '3' in the locale is "
           << "a lowercase character." << endl;
   else
      cout << "The character '3' in the locale is "
           << " not a lowercase character." << endl;
}

isprint

Menguji apakah elemen dalam lokal adalah karakter yang dapat dicetak.

template <class CharType>
bool isprint(CharType Ch, const locale& Loc)

Parameter

Ch
Elemen yang akan diuji.

Loc
Lokal yang berisi elemen yang akan diuji.

Tampilkan Nilai

true jika elemen yang diuji dapat dicetak; false jika tidak.

Keterangan

Fungsi templat mengembalikan use_facet<ctype<CharType>>( ). Loc is( ctype<CharType>:: print, ). Ch

Contoh

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

int main( )
{
   locale loc ( "German_Germany" );

   bool result1 = isprint ( 'L', loc );
   if ( result1 )
      cout << "The character 'L' in the locale is "
           << "a printable character." << endl;
   else
      cout << "The character 'L' in the locale is "
           << " not a printable character." << endl;

   bool result2 = isprint( '\t', loc );
   if ( result2 )
      cout << "The character 'backslash-t' in the locale is "
           << "a printable character." << endl;
   else
      cout << "The character 'backslash-t' in the locale is "
           << " not a printable character." << endl;

   bool result3 = isprint( '\n', loc );
   if ( result3 )
      cout << "The character 'backslash-n' in the locale is "
           << "a printable character." << endl;
   else
      cout << "The character 'backslash-n' in the locale is "
           << " not a printable character." << endl;
}

ispunct

Menguji apakah elemen dalam lokal adalah karakter tanda baca.

template <class CharType>
bool ispunct(CharType Ch, const locale& Loc)

Parameter

Ch
Elemen yang akan diuji.

Loc
Lokal yang berisi elemen yang akan diuji.

Tampilkan Nilai

true jika elemen yang diuji adalah karakter tanda baca; false jika tidak.

Keterangan

Fungsi templat mengembalikan use_facet<ctype<CharType>>( ). Loc is( ctype<CharType>:: punct, ). Ch

Contoh

// locale_ispunct.cpp
// compile with: /EHsc
#include <locale>
#include <iostream>

using namespace std;

int main( )
{
   locale loc ( "German_Germany" );
   bool result1 = ispunct ( 'L', loc );
   bool result2 = ispunct ( ';', loc );
   bool result3 = ispunct ( '*', loc );

   if ( result1 )
      cout << "The character 'L' in the locale is "
           << "a punctuation character." << endl;
   else
      cout << "The character 'L' in the locale is "
           << " not a punctuation character." << endl;

   if ( result2 )
      cout << "The character ';' in the locale is "
           << "a punctuation character." << endl;
   else
      cout << "The character ';' in the locale is "
           << " not a punctuation character." << endl;

   if ( result3 )
      cout << "The character '*' in the locale is "
           << "a punctuation character." << endl;
   else
      cout << "The character '*' in the locale is "
           << " not a punctuation character." << endl;
}

isspace

Menguji apakah elemen dalam lokal adalah karakter spasi kosong.

template <class CharType>
bool isspace(CharType Ch, const locale& Loc)

Parameter

Ch
Elemen yang akan diuji.

Loc
Lokal yang berisi elemen yang akan diuji.

Tampilkan Nilai

true jika elemen yang diuji adalah karakter spasi putih; false jika tidak.

Keterangan

Fungsi templat mengembalikan use_facet<ctype<CharType>>( ). Loc is( ctype<CharType>:: space, ). Ch

Contoh

// locale_isspace.cpp
// compile with: /EHsc
#include <locale>
#include <iostream>

using namespace std;

int main( )
{
   locale loc ( "German_Germany" );
   bool result1 = isspace ( 'L', loc );
   bool result2 = isspace ( '\n', loc );
   bool result3 = isspace ( ' ', loc );

   if ( result1 )
      cout << "The character 'L' in the locale is "
           << "a whitespace character." << endl;
   else
      cout << "The character 'L' in the locale is "
           << " not a whitespace character." << endl;

   if ( result2 )
      cout << "The character 'backslash-n' in the locale is "
           << "a whitespace character." << endl;
   else
      cout << "The character 'backslash-n' in the locale is "
           << " not a whitespace character." << endl;

   if ( result3 )
      cout << "The character ' ' in the locale is "
           << "a whitespace character." << endl;
   else
      cout << "The character ' ' in the locale is "
           << " not a whitespace character." << endl;
}

isupper

Menguji apakah elemen dalam lokal berada dalam huruf besar.

template <class CharType>
bool isupper(CharType Ch, const locale& Loc)

Parameter

Ch
Elemen yang akan diuji.

Loc
Lokal yang berisi elemen yang akan diuji.

Tampilkan Nilai

true jika elemen yang diuji adalah karakter huruf besar; false jika tidak.

Keterangan

Fungsi templat mengembalikan use_facet<ctype<CharType>>( ). Loc is( ctype<CharType>:: upper, ). Ch

Contoh

// locale_isupper.cpp
// compile with: /EHsc
#include <locale>
#include <iostream>

using namespace std;

int main( )
{
   locale loc ( "German_Germany" );
   bool result1 = isupper ( 'L', loc );
   bool result2 = isupper ( 'n', loc );
   bool result3 = isupper ( '3', loc );

   if ( result1 )
      cout << "The character 'L' in the locale is "
           << "a uppercase character." << endl;
   else
      cout << "The character 'L' in the locale is "
           << " not a uppercase character." << endl;

   if ( result2 )
      cout << "The character 'n' in the locale is "
           << "a uppercase character." << endl;
   else
      cout << "The character 'n' in the locale is "
           << " not a uppercase character." << endl;

   if ( result3 )
      cout << "The character '3' in the locale is "
           << "a uppercase character." << endl;
   else
      cout << "The character '3' in the locale is "
           << " not a uppercase character." << endl;
}

isxdigit

Menguji apakah elemen dalam lokal adalah karakter yang digunakan untuk mewakili angka heksadesimal.

template <class CharType>
bool isxdigit(CharType Ch, const locale& Loc)

Parameter

Ch
Elemen yang akan diuji.

Loc
Lokal yang berisi elemen yang akan diuji.

Tampilkan Nilai

true jika elemen yang diuji adalah karakter yang digunakan untuk mewakili angka heksadesimal; false jika tidak.

Keterangan

Fungsi templat mengembalikan use_facet<ctype<CharType>>( ). Loc is( ctype<CharType>:: xdigit, ). Ch

Digit heksadesimal menggunakan basis 16 untuk mewakili angka, menggunakan angka 0 hingga 9 ditambah huruf tidak peka huruf besar/kecil A hingga F untuk mewakili angka desimal 0 hingga 15.

Contoh

// locale_isxdigit.cpp
// compile with: /EHsc
#include <locale>
#include <iostream>

using namespace std;

int main( )
{
   locale loc ( "German_Germany" );
   bool result1 = isxdigit ( '5', loc );
   bool result2 = isxdigit ( 'd', loc );
   bool result3 = isxdigit ( 'q', loc );

   if ( result1 )
      cout << "The character '5' in the locale is "
           << "a hexidecimal digit-character." << endl;
   else
      cout << "The character '5' in the locale is "
           << " not a hexidecimal digit-character." << endl;

   if ( result2 )
      cout << "The character 'd' in the locale is "
           << "a hexidecimal digit-character." << endl;
   else
      cout << "The character 'd' in the locale is "
           << " not a hexidecimal digit-character." << endl;

   if ( result3 )
      cout << "The character 'q' in the locale is "
           << "a hexidecimal digit-character." << endl;
   else
      cout << "The character 'q' in the locale is "
           << " not a hexidecimal digit-character." << endl;
}

tolower

Mengonversi karakter menjadi huruf kecil.

template <class CharType>
CharType tolower(CharType Ch, const locale& Loc)

Parameter

Ch
Karakter yang akan dikonversi ke huruf kecil.

Loc
Lokal yang berisi karakter yang akan dikonversi.

Tampilkan Nilai

Karakter dikonversi ke huruf kecil.

Keterangan

Fungsi templat mengembalikan use_facet<ctype<CharType>>( ). Loc tolower( Ch).

Contoh

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

int main( )
{
   locale loc ( "German_Germany" );
   char result1 = tolower ( 'H', loc );
   cout << "The lower case of 'H' in the locale is: "
        << result1 << "." << endl;
   char result2 = tolower ( 'h', loc );
   cout << "The lower case of 'h' in the locale is: "
        << result2 << "." << endl;
   char result3 = tolower ( '$', loc );
   cout << "The lower case of '$' in the locale is: "
        << result3 << "." << endl;
}

toupper

Mengonversi karakter menjadi huruf besar.

template <class CharType>
CharType toupper(CharType Ch, const locale& Loc)

Parameter

Ch
Karakter yang akan dikonversi menjadi huruf besar.

Loc
Lokal yang berisi karakter yang akan dikonversi.

Tampilkan Nilai

Karakter dikonversi ke huruf besar.

Keterangan

Fungsi templat mengembalikan use_facet<ctype<CharType>>( ). Loc toupper( Ch).

Contoh

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

int main( )
{
   locale loc ( "German_Germany" );
   char result1 = toupper ( 'h', loc );
   cout << "The upper case of 'h' in the locale is: "
        << result1 << "." << endl;
   char result2 = toupper ( 'H', loc );
   cout << "The upper case of 'H' in the locale is: "
        << result2 << "." << endl;
   char result3 = toupper ( '$', loc );
   cout << "The upper case of '$' in the locale is: "
        << result3 << "." << endl;
}

use_facet

Mengembalikan referensi ke faset dari jenis tertentu yang disimpan dalam lokal.

template <class Facet>
const Facet& use_facet(const locale& Loc);

Parameter

Loc
Lokal const yang berisi jenis faset yang dirujuk.

Tampilkan Nilai

Referensi ke faset kelas Facet yang terkandung dalam lokal argumen.

Keterangan

Referensi ke faset yang dikembalikan oleh fungsi templat tetap valid selama ada salinan lokal yang berisi. Jika tidak ada objek faset kelas Facet yang tercantum dalam lokal argumen, fungsi akan melemparkan bad_cast pengecualian.

Contoh

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

int main( )
{
   locale loc1 ( "German_Germany" ), loc2 ( "English_Australia" );
   bool result1 = use_facet<ctype<char> > ( loc1 ).is(
   ctype_base::alpha, 'a'
);
   bool result2 = use_facet<ctype<char> > ( loc2 ).is( ctype_base::alpha, '!'
   );

   if ( result1 )
      cout << "The character 'a' in locale loc1 is alphabetic."
           << endl;
   else
      cout << "The character 'a' in locale loc1 is not alphabetic."
           << endl;

   if ( result2 )
      cout << "The character '!' in locale loc2 is alphabetic."
           << endl;
   else
      cout << "The character '!' in locale loc2 is not alphabetic."
           << endl;
}
The character 'a' in locale loc1 is alphabetic.
The character '!' in locale loc2 is not alphabetic.

Lihat juga

<lokal>