<locale>
函式
has_facet
isalnum
isalpha
iscntrl
isdigit
isgraph
islower
isprint
ispunct
isspace
isupper
isxdigit
tolower
toupper
use_facet
has_facet
測試特定的 facet 是否在指定的地區設定中儲存。
template <class Facet>
bool has_facet(const locale& Loc);
參數
Loc
要測試是否有 facet 存在的地區設定。
傳回值
true
如果地區設定已測試 Facet,則為 ; false
如果不是,則為 。
備註
此範本函式可用來在呼叫 use_facet
之前,先檢查地區設定中是否有列出非強制性 facet,以避免因 facet 不存在而擲回例外狀況。
範例
// 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
測試地區設定中的項目是否為字母或數字字元。
template <class CharType>
bool isalnum(CharType Ch, const locale& Loc)
參數
Ch
要測試的英數字元元素。
Loc
包含要測試之英數字元元素的地區設定。
傳回值
true
如果測試的專案為英數位元,則為 ; false
如果不是,則為 。
範例
// 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
測試地區設定中的元素是否為字母字元。
template <class CharType>
bool isalpha(CharType Ch, const locale& Loc)
參數
Ch
要測試的元素。
Loc
包含要測試之字母元素的地區設定。
傳回值
true
如果測試的專案依字母順序排列,則為 ; false
如果不是,則為 。
備註
樣本函式<會傳回 ctype<CharType>>( Loc
use_facet 。 is( ctype<CharType>:: alpha, Ch
。
範例
// 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
測試地區設定中的項目是否為控制字元。
template <class CharType>
bool iscntrl(CharType Ch, const locale& Loc)
參數
Ch
要測試的元素。
Loc
包含要測試之元素的地區設定。
傳回值
true
如果測試的專案是控制件字元,則為 ; false
如果不是,則為 。
備註
樣本函式<會傳回 ctype<CharType>>( Loc
use_facet 。 is( ctype<CharType>:: cntrl, Ch
。
範例
// 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
測試地區設定中的項目是否為數字字元。
template <class CharType>
bool isdigit(CharType Ch, const locale& Loc)
參數
Ch
要測試的元素。
Loc
包含要測試之元素的地區設定。
傳回值
true
如果測試的項目是數值字元,則為 ; false
如果不是,則為 。
備註
樣本函式<會傳回 ctype<CharType>>( Loc
use_facet 。 is( ctype<CharType>:: digit, Ch
。
範例
// 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
測試地區設定中的項目是否為英數字元或標點符號字元。
template <class CharType>
bool isgraph(CharType Ch, const locale& Loc)
參數
Ch
要測試的元素。
Loc
包含要測試之元素的地區設定。
傳回值
true
如果測試的專案是英數位元或標點符號字元,則為 ; false
如果不是,則為 。
備註
樣本函式<會傳回 ctype<CharType>>( Loc
use_facet 。 is( ctype<CharType>:: graph, Ch
。
範例
// 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
測試地區設定中的項目是否為小寫。
template <class CharType>
bool islower(CharType Ch, const locale& Loc)
參數
Ch
要測試的元素。
Loc
包含要測試之元素的地區設定。
傳回值
true
如果測試的項目是小寫字元,則為 ; false
如果不是,則為 。
備註
樣本函式<會傳回 ctype<CharType>>( Loc
use_facet 。 is( ctype<CharType>:: lower, Ch
。
範例
// 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
測試地區設定中的項目是否為可列印的字元。
template <class CharType>
bool isprint(CharType Ch, const locale& Loc)
參數
Ch
要測試的元素。
Loc
包含要測試之元素的地區設定。
傳回值
true
如果測試的專案是可列印的,則為 ; false
如果不是,則為 。
備註
樣本函式<會傳回 ctype<CharType>>( Loc
use_facet 。 is( ctype<CharType>:: print, Ch
。
範例
// 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
測試地區設定中的項目是否為標點符號字元。
template <class CharType>
bool ispunct(CharType Ch, const locale& Loc)
參數
Ch
要測試的元素。
Loc
包含要測試之元素的地區設定。
傳回值
true
如果測試的項目是標點符號字元,則為 ; false
如果不是,則為 。
備註
樣本函式<
會傳回 ctype<CharType>>( Loc
use_facet 。 is( ctype<CharType>:: punct, Ch
。
範例
// 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
測試地區設定中的項目是否為空白字元。
template <class CharType>
bool isspace(CharType Ch, const locale& Loc)
參數
Ch
要測試的元素。
Loc
包含要測試之元素的地區設定。
傳回值
true
如果測試的項目是空白,則為 ; false
如果不是,則為 。
備註
樣本函式<會傳回 ctype<CharType>>( Loc
use_facet 。 is( ctype<CharType>:: space, Ch
。
範例
// 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
測試地區設定中的元素是否為大寫。
template <class CharType>
bool isupper(CharType Ch, const locale& Loc)
參數
Ch
要測試的元素。
Loc
包含要測試之元素的地區設定。
傳回值
true
如果測試的專案是大寫字元,則為 ; false
如果不是,則為 。
備註
樣本函式<會傳回 ctype<CharType>>( Loc
use_facet 。 is( ctype<CharType>:: upper, Ch
。
範例
// 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
測試地區設定中的項目是否為用來表示十六進位數字的字元。
template <class CharType>
bool isxdigit(CharType Ch, const locale& Loc)
參數
Ch
要測試的元素。
Loc
包含要測試之元素的地區設定。
傳回值
true
如果測試的專案是用來表示十六進位數位的字元,則為 ; false
如果不是,則為 。
備註
樣本函式<會傳回 ctype<CharType>>( Loc
use_facet 。 is( ctype<CharType>:: xdigit, Ch
。
十六進位數字會使用以 16 為底數的方式來表示數字,其中是使用數字 0 到 9 再加上不區分大小寫的字母 A 到 F,來表示十進位數字 0 到 15。
範例
// 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
將字元轉換為小寫。
template <class CharType>
CharType tolower(CharType Ch, const locale& Loc)
參數
Ch
要轉換為小寫的字元。
Loc
包含要轉換之字元的地區設定。
傳回值
已轉換為小寫的字元。
備註
樣本函式<會傳回 ctype<CharType>>( Loc
use_facet 。 tolower( Ch
)。
範例
// 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
將字元轉換為大寫。
template <class CharType>
CharType toupper(CharType Ch, const locale& Loc)
參數
Ch
要轉換為大寫的字元。
Loc
包含要轉換之字元的地區設定。
傳回值
已轉換為大寫的字元。
備註
樣本函式<會傳回 ctype<CharType>>( Loc
use_facet 。 toupper( Ch
)。
範例
// 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
傳回儲存在地區設定中指定之類型的 facet 的參考。
template <class Facet>
const Facet& use_facet(const locale& Loc);
參數
Loc
包含所要參考之 facet 類型的常數地區設定。
傳回值
對 locale 引數內所包含之 Facet
類別 facet 的參考。
備註
只要有任何一個包含 facet 的地區設定複本存在,此範本函式所傳回對 facet 的參考就會保持有效。 如果 locale 引數中未列出任何這類 Facet
類別的 facet 物件,此函式就會擲回 bad_cast
例外狀況。
範例
// 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.