1、char、wchar_t、TCHAR
char :单字节变量类型,最多表示256个字符,
wchar_t :宽字节变量类型,用于表示Unicode字符,一般为16位或32位,
它实际定义在<string.h>里:typedef unsigned short wchar_t。
为了让编译器识别Unicode字符串,必须以在前面加一个“L”,定义宽字节类型方法如下:
wchar_t c = `A' ;
wchar_t * p = L"Hello!" ;
wchar_t a[] = L"Hello!" ;
#ifdef UNICODE
typedef char TCHAR;
#else
typede wchar_t TCHAR;
#endif
_T(x)与__TEXT(quote)与TEXT(quote)三者相等
#ifdef UNICODE
#define _T(x) L##x
#else
#define _T(x) x
#endif
#ifdef UNICODE
#define __TEXT(quote) L##quote
#else
#define __TEXT(quote) quote
#endif
#define TEXT(quote) __TEXT(quote)
2、strcpy, wcscpy, _mbscpy, _tcscpy
函数原型:
char *strcpy( char *strDestination, const char *strSource );
wchar_t *wcscpy( wchar_t *strDestination, const wchar_t *strSource );
unsigned char *_mbscpy( unsigned char *strDestination, const unsigned char *strSource );
#ifdef UNICODE
#define _tcscpy wcscpy
#else
#define _tcscpy strcpy
#endif
例子:
//如果你想使用ANSI字符串,那么请使用这一套写法:
char szString[100];
strcpy(szString,"test");
//如果你想使用Unicode字符串,那么请使用这一套:
wchar_t szString[100];
wcscpy(szString,L"test");
//如果你想通过定义_UNICODE宏,而编译ANSI或者Unicode字符串代码:
TCHAR szString[100];
_tcscpy(szString,_TEXT("test"));
TCHAR.H Routine | _UNICODE & _MBCS Not Defined | _MBCS Defined | _UNICODE Defined |
_tcscpy | strcpy | _mbscpy | wcscpy |
3、strcat, wcscat, _mbscat, _tcscat
char *strcat( char *strDestination, const char *strSource );
wchar_t *wcscat( wchar_t *strDestination, const wchar_t *strSource );
unsigned char *_mbscat( unsigned char *strDestination, const unsigned char *strSource );
template <size_t size>
char *strcat( char (&strDestination)[size], const char *strSource ); // C++ only
template <size_t size>
wchar_t *wcscat( wchar_t (&strDestination)[size], const wchar_t *strSource ); // C++ only
template <size_t size>
unsigned char *_mbscat( unsigned char (&strDestination)[size], const unsigned char *strSource ); // C++ only
TCHAR.H routine | _UNICODE & _MBCS not defined | _MBCS defined | _UNICODE defined |
---|---|---|---|
_tcscat | strcat | _mbscat | wcscat |
功能:把strSource所指字符串添加到strDestination结尾处,覆盖strDestination结尾处的'\0'并添加'\0'.
4、
main( int argc, char *argv[ ], char *envp[ ]);
wmain( int argc, wchar_t *argv[ ], wchar_t *envp[ ]);
#ifdef UNICODE
#define _tmain wmain
#define _tWinMain wWinMain
#else
#define _tmain main
#define _tWinMain WinMain
#endif