Kommentar
Åtkomst till den här sidan kräver auktorisering. Du kan prova att logga in eller ändra kataloger.
Åtkomst till den här sidan kräver auktorisering. Du kan prova att ändra kataloger.
Rubriken <locale> innehåller följande funktioner:
has_facet
Testar om en viss aspekt lagras på ett angivet språk.
template <class Facet>
bool has_facet(const locale& Loc);
Parameterar
Loc
Språkvarianten som ska testas för förekomsten av en aspekt.
Returvärde
true om språkvarianten har fasetteringstestad för; false om det inte gör det.
Anmärkningar
Mallfunktionen är användbar för att kontrollera om icke-hanteringsfasetter visas i en språkvariant innan use_facet anropas för att undvika det undantag som skulle utlösas om den inte fanns.
Exempel
// 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
Testar om ett element i ett språk är ett alfabetiskt eller numeriskt tecken.
template <class CharType>
bool isalnum(CharType Ch, const locale& Loc)
Parameterar
Ch
Det alfanumeriska element som ska testas.
Loc
Språkvarianten som innehåller det alfanumeriska element som ska testas.
Returvärde
true om det testade elementet är alfanumeriskt; false om det inte är det.
Exempel
// 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
Testar om ett element i ett språk är ett alfabetiskt tecken.
template <class CharType>
bool isalpha(CharType Ch, const locale& Loc)
Parameterar
Ch
Elementet som ska testas.
Loc
Språkvarianten som innehåller det alfabetiska element som ska testas.
Returvärde
true om det testade elementet är alfabetiskt; false om det inte är det.
Anmärkningar
Mallfunktionen returnerar use_facet<ctype<CharType>>(Loc).
is( ctype<CharType>:: alpha, Ch).
Exempel
// 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
Testar om ett element i ett språk är ett kontrolltecken.
template <class CharType>
bool iscntrl(CharType Ch, const locale& Loc)
Parameterar
Ch
Elementet som ska testas.
Loc
Språkvarianten som innehåller elementet som ska testas.
Returvärde
true om elementet som testas är ett kontrolltecken; false om det inte är det.
Anmärkningar
Mallfunktionen returnerar use_facet<ctype<CharType>>(Loc).
is( ctype<CharType>:: cntrl, Ch).
Exempel
// 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
Testar om ett element i ett språk är ett numeriskt tecken.
template <class CharType>
bool isdigit(CharType Ch, const locale& Loc)
Parameterar
Ch
Elementet som ska testas.
Loc
Språkvarianten som innehåller elementet som ska testas.
Returvärde
true om det testade elementet är ett numeriskt tecken. false om det inte är det.
Anmärkningar
Mallfunktionen returnerar use_facet<ctype<CharType>>(Loc).
is( ctype<CharType>:: digit, Ch).
Exempel
// 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
Testar om ett element i ett språk är ett alfanumeriskt tecken eller skiljetecken.
template <class CharType>
bool isgraph(CharType Ch, const locale& Loc)
Parameterar
Ch
Elementet som ska testas.
Loc
Språkvarianten som innehåller elementet som ska testas.
Returvärde
true om det testade elementet är ett alfanumeriskt tecken eller ett skiljetecken. false om det inte är det.
Anmärkningar
Mallfunktionen returnerar use_facet<ctype<CharType>>(Loc).
is( ctype<CharType>:: graph, Ch).
Exempel
// 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
Testar om ett element i ett språk är gemener.
template <class CharType>
bool islower(CharType Ch, const locale& Loc)
Parameterar
Ch
Elementet som ska testas.
Loc
Språkvarianten som innehåller elementet som ska testas.
Returvärde
true om elementet som testas är ett gemener. false om det inte är det.
Anmärkningar
Mallfunktionen returnerar use_facet<ctype<CharType>>(Loc).
is( ctype<CharType>:: lower, Ch).
Exempel
// 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
Testar om ett element i ett språk är ett utskrivbart tecken.
template <class CharType>
bool isprint(CharType Ch, const locale& Loc)
Parameterar
Ch
Elementet som ska testas.
Loc
Språkvarianten som innehåller elementet som ska testas.
Returvärde
true om det testade elementet är utskrivbart; false om det inte är det.
Anmärkningar
Mallfunktionen returnerar use_facet<ctype<CharType>>(Loc).
is( ctype<CharType>:: print, Ch).
Exempel
// 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
Testar om ett element i ett språk är ett skiljetecken.
template <class CharType>
bool ispunct(CharType Ch, const locale& Loc)
Parameterar
Ch
Elementet som ska testas.
Loc
Språkvarianten som innehåller elementet som ska testas.
Returvärde
true om det testade elementet är ett skiljetecken; false om det inte är det.
Anmärkningar
Mallfunktionen returnerar use_facet<ctype<CharType>>(Loc).
is( ctype<CharType>:: punct, Ch).
Exempel
// 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
Testar om ett element i ett språk är ett blankstegstecken.
template <class CharType>
bool isspace(CharType Ch, const locale& Loc)
Parameterar
Ch
Elementet som ska testas.
Loc
Språkvarianten som innehåller elementet som ska testas.
Returvärde
true om elementet som testas är ett blankstegstecken; false om det inte är det.
Anmärkningar
Mallfunktionen returnerar use_facet<ctype<CharType>>(Loc).
is( ctype<CharType>:: space, Ch).
Exempel
// 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
Testar om ett element i ett språk är i versaler.
template <class CharType>
bool isupper(CharType Ch, const locale& Loc)
Parameterar
Ch
Elementet som ska testas.
Loc
Språkvarianten som innehåller elementet som ska testas.
Returvärde
true om elementet som testas är ett versalt tecken. false om det inte är det.
Anmärkningar
Mallfunktionen returnerar use_facet<ctype<CharType>>(Loc).
is( ctype<CharType>:: upper, Ch).
Exempel
// 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
Testar om ett element i ett språk är ett tecken som används för att representera ett hexadecimalt tal.
template <class CharType>
bool isxdigit(CharType Ch, const locale& Loc)
Parameterar
Ch
Elementet som ska testas.
Loc
Språkvarianten som innehåller elementet som ska testas.
Returvärde
true om det testade elementet är ett tecken som används för att representera ett hexadecimalt tal; false om det inte är det.
Anmärkningar
Mallfunktionen returnerar use_facet<ctype<CharType>>(Loc).
is( ctype<CharType>:: xdigit, Ch).
Hexadecimala siffror använder bas 16 för att representera tal, med hjälp av talen 0 till 9 plus skiftlägesokänsliga bokstäver A till F för att representera decimaltalen 0 till 15.
Exempel
// 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
Konverterar ett tecken till gemener.
template <class CharType>
CharType tolower(CharType Ch, const locale& Loc)
Parameterar
Ch
Tecknet som ska konverteras till gemener.
Loc
Språkvarianten som innehåller det tecken som ska konverteras.
Returvärde
Tecknet konverterades till gemener.
Anmärkningar
Mallfunktionen returnerar use_facet<ctype<CharType>>(Loc).
tolower(Ch).
Exempel
// 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
Konverterar ett tecken till versaler.
template <class CharType>
CharType toupper(CharType Ch, const locale& Loc)
Parameterar
Ch
Tecknet som ska konverteras till versaler.
Loc
Språkvarianten som innehåller det tecken som ska konverteras.
Returvärde
Tecknet konverterades till versaler.
Anmärkningar
Mallfunktionen returnerar use_facet<ctype<CharType>>(Loc).
toupper(Ch).
Exempel
// 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
Returnerar en referens till en aspekt av en angiven typ som lagras i ett språk.
template <class Facet>
const Facet& use_facet(const locale& Loc);
Parameterar
Loc
Den beständighetsinställning som innehåller den typ av fasetter som refereras till.
Returvärde
En referens till aspekten av klassen Facet som finns i argumentspråket.
Anmärkningar
Referensen till den fasetter som returneras av mallfunktionen är giltig så länge det finns en kopia av den innehållande språkvarianten. Om inget sådant fasetteringsobjekt för klassen Facet visas i argumentspråket utlöser funktionen ett bad_cast undantag.
Exempel
// 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.