char与wchar_t函数对照表

#include <ctype.h>
#include <string.h>

1、把多字符把转换成宽字符

_CRTIMP size_t    __cdecl mbstowcs(wchar_t *, const wchar* ,size_t);

2、将宽字符转换成多字符

_CRTIMP size_t    __cdecl wcstombs(char *mbstr, const wchar_t *wcstr, size_t count);

3、计算字符数

size_t __cdecl strlen(const char *);
_INTRIMP size_t    __cdecl wcslen(const wchar_t *); 

4、比较字符串

int    __cdecl strcmp(const char *, const char *);
_INTRIMP int  __cdecl wcscmp(const wchar_t *, const wchar_t *);

5、拼接字符串

char * __cdecl strcat(char *, const char *);
_INTRIMP wchar_t * __cdecl wcscat(wchar_t *, const wchar_t *);

6、拷贝字符串

char * __cdecl strcpy(char *, const char *);
_INTRIMP wchar_t * __cdecl wcscpy(wchar_t *, const wchar_t *);

7、查找字符 返回地址

_CRTIMP char * __cdecl strchr(const char *, char);
_CRTIMP wchar_t * __cdecl wcschr(const wchar_t *, wchar_t);

8、查找字符 返回位置

_CRTIMP size_t __cdecl strcspn(const char *, const char *);
_CRTIMP size_t    __cdecl wcscspn(const wchar_t *, const wchar_t *);

9、查找完全匹配的子字符串

_CRTIMP char * __cdecl strstr(const char *, const char *);
_CRTIMP wchar_t * __cdecl wcsstr(const wchar_t *, const wchar_t *);

10、按位置拼接字符串 const char* 前n的字符

_CRTIMP char * __cdecl strncat(char *, const char *, size_t);
_CRTIMP wchar_t * __cdecl wcsncat(wchar_t *, const wchar_t *, size_t);

11、分割字符串

_CRTIMP char * __cdecl strtok(char *, const char *);
_CRTIMP wchar_t * __cdecl wcstok(wchar_t *, const wchar_t *);

12、拷贝字符串 const char* 前n的字符

_CRTIMP char * __cdecl strncpy(char *, const char *, size_t);
_CRTIMP wchar_t * __cdecl wcsncpy(wchar_t *, const wchar_t *, size_t);

13、比较字符串 前n个字符

_CRTIMP int    __cdecl strncmp(const char *, const char *, size_t);
_CRTIMP int       __cdecl wcsncmp(const wchar_t *, const wchar_t *, size_t);

14、比较字符串,不区分字母的大小写

_CRTIMP int     __cdecl _stricmp(const char *, const char *);
_CRTIMP int       __cdecl _wcsicmp(const wchar_t *, const wchar_t *);

15、比较字符串的前n个字符串字典序的大小,不区分字母大小写

_CRTIMP int     __cdecl _strnicmp(const char *, const char *, size_t);
_CRTIMP int       __cdecl _wcsnicmp(const wchar_t *, const wchar_t *, size_t);

16、检验参数1中的字符,当被检验字符在参数2中也包含时,返回该字符位置,空字符不包括在内。

_CRTIMP char * __cdecl strpbrk(const char *, const char *);
_CRTIMP wchar_t * __cdecl wcspbrk(const wchar_t *, const wchar_t *);

17、查找一个字符在另一个字符串中末次出现的位置

_CRTIMP char * __cdecl strrchr(const char *, char);
_CRTIMP wchar_t * __cdecl wcsrchr(const wchar_t *, wchar_t);

18、从参数1开头计算连续字符,如字符完全是参数2中的字符。返回开头连续包含的字符数目。

_CRTIMP size_t __cdecl strspn(const char *, const char *);
_CRTIMP size_t    __cdecl wcsspn(const wchar_t *, const wchar_t *);

19、复制字符串 使用完后需要free()释放内存,可直接复制CString中的字符串

_CRTIMP char * __cdecl _strdup(const char *);
_CRTIMP wchar_t * __cdecl _wcsdup(const wchar_t *);

20、将一个串中的前N个字符都设为指定字符

_CRTIMP char * __cdecl _strnset(char *, char, size_t);
_CRTIMP wchar_t * __cdecl _wcsnset(wchar_t *, wchar_t, size_t);

21、把字符串的所有字符的顺序颠倒过来(不包括空字符NULL)。

_CRTIMP char * __cdecl _strrev(char *);
_CRTIMP wchar_t * __cdecl _wcsrev(wchar_t *);

22、将一个串中的所有字符都设为指定字符,不建议使用,该函数不会检查‘\0’,容易导致内存错误

char * __cdecl _strset(char *, int);
_CRTIMP wchar_t * __cdecl _wcsset(wchar_t *, wchar_t);

23、将字符串转换为小写形式

_CRTIMP char * __cdecl _strlwr(char *);
_CRTIMP wchar_t * __cdecl _wcslwr(wchar_t *);

24、将字符串转换为大写形式

_CRTIMP char * __cdecl _strupr(char *);
_CRTIMP wchar_t * __cdecl _wcsupr(wchar_t *);

25、把字符转换成小写字母,非字母字符不做出处理

_CRTIMP char    __cdecl tolower(char);
_CRTIMP wchar_t towlower(wchar_t);

26、把字符转换成大写字母,非字母字符不做出处理

_CRTIMP int    __cdecl toupper(int);
_CRTIMP wchar_t towupper(wchar_t);

阅读上述原文,请点击这里

《windows核心编程》P13-14 中写道:
声明Unicode字符和字符串的方法如下所示

wchar_t c=L'A';
wchar_t szBuffer[100]=L"A String";

在WinNT.h中定义了一系列能为我们提供大量方便的数据类型,可以用它来处理字符指针和字符串指针

typedef char CHAR;
typedef wchar_t WCHAR;

typedef CHAR *PCHAR;
typedef CHAR *PSTR;
typedef CONST CHAR *PCSTR

typedef WCHAR *PWCHAR;
typedef WCHAR *PWSTR;
typedef CONST WCHAR *PCWSTR;

另外,WinNT.h还定义了下面的类型和宏,使用ANSI或Unicode字符/字符串都能通过编译。

#ifdef UNICODE

typedef WCHAR TCHAR,*PTCHAR,PTSTR;
typedef CONST WCHAR *PCTSTR;
#define __TEXT(quote) quote//r_winnt
#define __TEXT(quote) L##quote

#else

typedef CHAR TCHAR, *PTCHAR,PTSTR;
typedef CONST CHAR *PCTSTR;
#define __TEXT(quote) quote

#endif
#define TEXT(quote) __TEXT(quote)

如下示例,都可以通过编译,推荐此方法:

TCHAR C = TEXT('A');
TCHAR szBuffer[100] = TEXT("A String");

宽字节编写的小demo

#include<iostream>
#include<windows.h>
using namespace std;
int main()
{
    setlocale(LC_ALL, "");

    TCHAR path[MAX_PATH];
    GetSystemDirectory(path,MAX_PATH);
    wcsncat(path,TEXT("\\cmd.exe"),9);
    wcout<<path<<endl;

    WCHAR s[] = L"你好";
    wcout<<s<<endl;
    getwchar();
    return 0;
}

这里写图片描述

其中wout输出中文的解决方法:
点击这里或打开下面链接
http://blog.csdn.net/ax614/article/details/6694625

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值