用transform怎么实现希腊字母、俄文字母的大小写转换
用transform如何实现希腊字母、俄文字母的大小写转换。
我转换英文大小写的代码如下:
transform(tmp.begin(), tmp.end(), tmp.begin(), tolower);
换在希腊字母,就不行了,不知是不是tolower参数不对。
------解决思路----------------------
transform只是针对ASCII字符的吧,你的希腊字母需要自己写。
------解决思路----------------------
使用Unicode字符集或多字节字符集,设置相应的locale
参考CRT\SRC\GETQLOC.C的内容。
------解决思路----------------------
tolower, _tolower, towlower
Convert character to lowercase.
int tolower( int c );
int _tolower( int c );
int towlower( wint_t c );
Routine Required Header Compatibility
tolower <stdlib.h> and <ctype.h> ANSI, Win 95, Win NT
_tolower <ctype.h> Win 95, Win NT
towlower <ctype.h> or <wchar.h> ANSI, Win 95, Win NT
For additional compatibility information, see Compatibility in the Introduction.
Libraries
LIBC.LIB Single thread static library, retail version
LIBCMT.LIB Multithread static library, retail version
MSVCRT.LIB Import library for MSVCRT.DLL, retail version
Return Value
Each of these routines converts a copy of c, if possible, and returns the result. There is no return value reserved to indicate an error.
Parameter
c
Character to convert
Remarks
Each of these routines converts a given uppercase letter to a lowercase letter if possible and appropriate.
Data Conversion Routines
See Also is Routines, to Functions Overview
Example
/* TOUPPER.C: This program uses toupper and tolower to
* analyze all characters between 0x0 and 0x7F. It also
* applies _toupper and _tolower to any code in this
* range for which these functions make sense.
*/
#include <conio.h>
#include <ctype.h>
#include <string.h>
char msg[] = "Some of THESE letters are Capitals\r\n";
char *p;
void main( void )
{
_cputs( msg );
/* Reverse case of message. */
for( p = msg; p < msg + strlen( msg ); p++ )
{
if( islower( *p ) )
_putch( _toupper( *p ) );
else if( isupper( *p ) )
_putch( _tolower( *p ) );
else
_putch( *p );
}
}
Output
Some of THESE letters are Capitals
sOME OF these LETTERS ARE cAPITALS
The tolower and toupper routines:
Are dependent on the LC_CTYPE category of the current locale (tolower calls isupper and toupper calls islower).
Convert c if c represents a convertible letter of the appropriate case in the current locale and the opposite case exists for that locale. Otherwise, c is unchanged.
The _tolower and _toupper routines:
Are locale-independent, much faster versions of tolower and toupper.
Can be used only when isascii(c) and either isupper(c) or islower(c), respectively, are true.
Have undefined results if c is not an ASCII letter of the appropriate case for converting.
The towlower and towupper functions return a converted copy of c if and only if both of the following conditions are true. Otherwise, c is unchanged.
c is a wide character of the appropriate case (that is, for which iswupper or iswlower, respectively, is true).
There is a corresponding wide character of the target case (that is, for which iswlower or iswupper, respectively, is true).
我转换英文大小写的代码如下:
transform(tmp.begin(), tmp.end(), tmp.begin(), tolower);
换在希腊字母,就不行了,不知是不是tolower参数不对。
------解决思路----------------------
transform只是针对ASCII字符的吧,你的希腊字母需要自己写。
------解决思路----------------------
使用Unicode字符集或多字节字符集,设置相应的locale
参考CRT\SRC\GETQLOC.C的内容。
------解决思路----------------------
tolower, _tolower, towlower
Convert character to lowercase.
int tolower( int c );
int _tolower( int c );
int towlower( wint_t c );
Routine Required Header Compatibility
tolower <stdlib.h> and <ctype.h> ANSI, Win 95, Win NT
_tolower <ctype.h> Win 95, Win NT
towlower <ctype.h> or <wchar.h> ANSI, Win 95, Win NT
For additional compatibility information, see Compatibility in the Introduction.
Libraries
LIBC.LIB Single thread static library, retail version
LIBCMT.LIB Multithread static library, retail version
MSVCRT.LIB Import library for MSVCRT.DLL, retail version
Return Value
Each of these routines converts a copy of c, if possible, and returns the result. There is no return value reserved to indicate an error.
Parameter
c
Character to convert
Remarks
Each of these routines converts a given uppercase letter to a lowercase letter if possible and appropriate.
Data Conversion Routines
See Also is Routines, to Functions Overview
Example
/* TOUPPER.C: This program uses toupper and tolower to
* analyze all characters between 0x0 and 0x7F. It also
* applies _toupper and _tolower to any code in this
* range for which these functions make sense.
*/
#include <conio.h>
#include <ctype.h>
#include <string.h>
char msg[] = "Some of THESE letters are Capitals\r\n";
char *p;
void main( void )
{
_cputs( msg );
/* Reverse case of message. */
for( p = msg; p < msg + strlen( msg ); p++ )
{
if( islower( *p ) )
_putch( _toupper( *p ) );
else if( isupper( *p ) )
_putch( _tolower( *p ) );
else
_putch( *p );
}
}
Output
Some of THESE letters are Capitals
sOME OF these LETTERS ARE cAPITALS
The tolower and toupper routines:
Are dependent on the LC_CTYPE category of the current locale (tolower calls isupper and toupper calls islower).
Convert c if c represents a convertible letter of the appropriate case in the current locale and the opposite case exists for that locale. Otherwise, c is unchanged.
The _tolower and _toupper routines:
Are locale-independent, much faster versions of tolower and toupper.
Can be used only when isascii(c) and either isupper(c) or islower(c), respectively, are true.
Have undefined results if c is not an ASCII letter of the appropriate case for converting.
The towlower and towupper functions return a converted copy of c if and only if both of the following conditions are true. Otherwise, c is unchanged.
c is a wide character of the appropriate case (that is, for which iswupper or iswlower, respectively, is true).
There is a corresponding wide character of the target case (that is, for which iswlower or iswupper, respectively, is true).