TCHAR与C语言string.h的对应关系

Windows C编程过程中,常常涉及到字符串处理的问题。

如果你想用纯C来进行Windows开发,那么你可以用C语言的标准库,幸运的是C语言标准库已经加入了Unicode的支持,例如:

strchr()------------------wcschr()
wcs是wide char string的缩写,原来相应的字符串操作函数只需要将str替换为wcs即可。
就现在来说,一般都用Unicode了,但是当需要在ANSI和Unicode两个环境之间切换的时候,TCHAR的作用就显的尤为重要了。
使用TCHAR的话就省掉了分别使用两种函数的麻烦了。
如果使用VS来进行项目建立的时候,你会发现几个有趣的函数。
_tmain()---------------这个一个宏,位于tchar.h
定义Unicode后,#define _tmain   wWinMain()被执行。

         没有定义Unicode后,#define _tmain WinMain()被执行。

CreateWindow()----------也是一个宏,位于WinUser.h

定义Unicode后,#define CreateWindow CreateWindowW

没有定义,#define CreateWindow   CreateWindowA

可以说Win32 SDK的代码被Unicode分为两个部分。Unidode和ANSI,在WinUser.h中,很多函数都是这样定义的。Windows SDK通过宏来屏蔽函数的差异。

总而言之,如果你要想一致(表面上)的处理Unicode和ANSI,那么就要使用TCHAR及相关的字符串处理类。

宏定义------------替换,在预处理阶段。

typedef------------重命名,编译阶段。

以下是TCHAR相关的字符串处理函数(也是宏)

Generic-text routine nameSBCS (_UNICODE & MBCS not defined)_MBCS defined_UNICODE defined
_cgetts_cgets_cgets_cgetws
_cgetts_s_cgets_s_cgets_s_cgetws_s
_cputts_cputs_cputs_cputws
_fgettcfgetcfgetcfgetwc
_fgettchar_fgetchar_fgetchar_fgetwchar
_fgettsfgetsfgetsfgetws
_fputtcfputcfputcfputwc
_fputtchar_fputchar_fputchar_fputwchar
_fputtsfputsfputsfputws
_ftprintffprintffprintffwprintf
_ftprintf_sfprintf_sfprintf_sfwprintf_s
_ftscanffscanffscanffwscanf
_ftscanf_sfscanf_sfscanf_sfwscanf_s
_gettcgetcgetcgetwc
_gettch_getch_getch_getwch
_gettchargetchargetchargetwchar
_gettche_getche_getche_getwche
_gettsgetsgetsgetws
_getts_sgets_sgets_sgetws_s
_istalnumisalnum_ismbcalnumiswalnum
_istalphaisalpha_ismbcalphaiswalpha
_istasciiisasciiisasciiiswascii
_istcntrliscntrliscntrliswcntrl
_istdigitisdigit_ismbcdigitiswdigit
_istgraphisgraph_ismbcgraphiswgraph
_istleadAlways returns false_ismbbleadAlways returns false
_istleadbyteAlways returns falseisleadbyteAlways returns false
_istlegalAlways returns true_ismbclegalAlways returns true
_istlowerislower_ismbcloweriswlower
_istprintisprint_ismbcprintiswprint
_istpunctispunct_ismbcpunctiswpunct
_istspaceisspace_ismbcspaceiswspace
_istupperisupper_ismbcupperiswupper
_istxdigitisxdigitisxdigitiswxdigit
_itot_itoa_itoa_itow
_itot_s_itoa_s_itoa_s_itow_s
_ltot_ltoa_ltoa_ltow
_ltot_s_ltoa_s_ltoa_s_ltow_s
_puttcputcputcputwc
_puttch_putch_putch_putwch
_puttcharputcharputcharputwchar
_puttsputsputs_putws
_sctprintf_scprintf_scprintf_scwprintf
_sntprintf_snprintf_snprintf_snwprintf
_sntprintf_s_snprintf_s_snprintf_s_snwprintf_s
_sntscanf_snscanf_snscanf_snwscanf
_sntscanf_s_snscanf_s_snscanf_s_snwscanf_s
_stprintfsprintfsprintfswprintf
_stprintf_ssprintf_ssprintf_sswprintf_s
_stscanfsscanfsscanfswscanf
_stscanf_ssscanf_ssscanf_sswscanf_s
_taccess_access_access_waccess
_taccess_s_access_s_access_s_waccess_s
_tasctimeasctimeasctime_wasctime
_tasctime_sasctime_sasctime_s_wasctime_s
_tccmpMaps to macro or inline function_mbsncmpMaps to macro or inline function
_tccpyMaps to macro or inline function_mbccpyMaps to macro or inline function
_tccpy_sstrcpy_s_mbccpy_swcscpy_s
_tchdir_chdir_chdir_wchdir
_tclenMaps to macro or inline function_mbclenMaps to macro or inline function
_tchmod_chmod_chmod_wchmod
_tcprintf_cprintf_cprintf_cwprintf
_tcprintf_s_cprintf_s_cprintf_s_cwprintf_s
_tcreat_creat_creat_wcreat
_tcscanf_cscanf_cscanf_cwscanf
_tcscanf_s_cscanf_s_cscanf_s_cwscanf_s
_tcscatstrcat_mbscatwcscat
_tcscat_sstrcat_s_mbscat_swcscat_s
_tcschrstrchr_mbschrwcschr
_tcsclenstrlen_mbslenwcslen
_tcsclen_sstrlen_s_mbslen_swcslen_s
_tcscmpstrcmp_mbscmpwcscmp
_tcscollstrcoll_mbscollwcscoll
_tcscpystrcpy_mbscpywcscpy
_tcscpy_sstrcpy_s_mbscpy_swcscpy_s
_tcscspnstrcspn_mbscspnwcscspn
_tcsdec_strdec_mbsdec_wcsdec
_tcsdup_strdup_mbsdup_wcsdup
_tcserrorstrerrorstrerror_wcserror
_tcserror_sstrerror_sstrerror_s_wcserror_s
_tcsftimestrftimestrftimewcsftime
_tcsicmp_stricmp_mbsicmp_wcsicmp
_tcsicoll_stricoll_mbsicoll_wcsicoll
_tcsinc_strinc_mbsinc_wcsinc
_tcslenstrlenstrlenwcslen
_tcslen_sstrlen_sstrlen_swcslen_s
_tcslwr_strlwr_mbslwr_wcslwr
_tcslwr_s_strlwr_s_mbslwr_s_wcslwr_s
_tcsnbcnt_strncnt_mbsnbcnt_wcsncnt
_tcsncatstrncat_mbsnbcatwcsncat
_tcsncat_sstrncat_s_mbsnbcat_swcsncat_s
_tcsnccatstrncat_mbsncatwcsncat
_tcsnccmpstrncmp_mbsncmpwcsncmp
_tcsnccmp_sstrncmp_s_mbsncmp_swcsncmp_s
_tcsnccoll_strncoll_mbsncoll_wcsncoll
_tcsncmpstrncmp_mbsnbcmpwcsncmp
_tcsnccnt_strncnt_mbsnccnt_wcsncnt
_tcsnccpystrncpy_mbsncpywcsncpy
_tcsnccpy_sstrncpy_s_mbsncpy_swcsncpy_s
_tcsncicmp_strnicmp_mbsnicmp_wcsnicmp
_tcsncicoll_strnicoll_mbsnicoll_wcsnicoll
_tcsncpystrncpy_mbsnbcpywcsncpy
_tcsncpy_sstrncpy_s_mbsnbcpy_swcsncpy_s
_tcsncset_strnset_mbsnset_wcsnset
_tcsnextc_strnextc_mbsnextc_wcsnextc
_tcsnicmp_strnicmp_mbsnbicmp_wcsnicmp
_tcsnicoll_strnicoll_mbsnbicoll_wcsnicoll
_tcsninc_strninc_mbsninc_wcsninc
_tcsnccnt_strncnt_mbsnccnt_wcsncnt
_tcsnset_strnset_mbsnbset_wcsnset
_tcspbrkstrpbrk_mbspbrkwcspbrk
_tcsspnp_strspnp_mbsspnp_wcsspnp
_tcsrchrstrrchr_mbsrchrwcsrchr
_tcsrev_strrev_mbsrev_wcsrev
_tcsset_strset_mbsset_wcsset
_tcsspnstrspn_mbsspnwcsspn
_tcsstrstrstr_mbsstrwcsstr
_tcstodstrtodstrtodwcstod
_tcstoi64_strtoi64_strtoi64_wcstoi64
_tcstokstrtok_mbstokwcstok
_tcstok_sstrtok_s_mbstok_swcstok_s
_tcstolstrtolstrtolwcstol
_tcstoui64_strtoui64_strtoui64_wcstoui64
_tcstoulstrtoulstrtoulwcstoul
_tcsupr_strupr_mbsupr_wcsupr
_tcsupr_s_strupr_s_mbsupr_s_wcsupr_s
_tcsxfrmstrxfrmstrxfrmwcsxfrm
_tctimectimectime_wctime
_tctime_sctime_sctime_s_wctime_s
_tctime32_ctime32_ctime32_wctime32
_tctime32_s_ctime32_s_ctime32_s_wctime32_s
_tctime64_ctime64_ctime64_wctime64
_tctime64_s_ctime64_s_ctime64_s_wctime64_s
_texecl_execl_execl_wexecl
_texecle_execle_execle_wexecle
_texeclp_execlp_execlp_wexeclp
_texeclpe_execlpe_execlpe_wexeclpe
_texecv_execv_execv_wexecv
_texecve_execve_execve_wexecve
_texecvp_execvp_execvp_wexecvp
_texecvpe_execvpe_execvpe_wexecvpe
_tfdopen_fdopen_fdopen_wfdopen
_tfindfirst_findfirst_findfirst_wfindfirst
_tfindnext_findnext_findnext_wfindnext
_tfindnext32_findnext32_findnext32_wfindnext32
_tfindnext64_findnext64_findnext64_wfindnext64
_tfindnexti64_findnexti64_findnexti64_wfindnexti64
_tfindnexti6432_findnexti6432_findnexti6432_wfindnexti6432
_tfindnext32i64_findnext32i64_findnext32i64_wfindnext32i64
_tfopenfopenfopen_wfopen
_tfopen_sfopen_sfopen_s_wfopen_s
_tfreopenfreopenfreopen_wfreopen
_tfreopen_sfreopen_sfreopen_s_wfreopen_s
_tfsopen_fsopen_fsopen_wfsopen
_tfullpath_fullpath_fullpath_wfullpath
_tgetcwd_getcwd_getcwd_wgetcwd
_tgetdcwd_getdcwd_getdcwd_wgetdcwd
_tgetenvgetenvgetenv_wgetenv
_tgetenv_sgetenv_sgetenv_s_wgetenv_s
_tmainmainmainwmain
_tmakepath_makepath_makepath_wmakepath
_tmakepath_s_makepath_s_makepath_s_wmakepath_s
_tmkdir_mkdir_mkdir_wmkdir
_tmktemp_mktemp_mktemp_wmktemp
_tmktemp_s_mktemp_s_mktemp_s_wmktemp_s
_topen_open_open_wopen
_topen_s_open_s_open_s_wopen_s
_totlowertolower_mbctolowertowlower
_totuppertoupper_mbctouppertowupper
_tperrorperrorperror_wperror
_tpopen_popen_popen_wpopen
_tprintfprintfprintfwprintf
_tprintf_sprintf_sprintf_swprintf_s
_tputenv_putenv_putenv_wputenv
_tputenv_s_putenv_s_putenv_s_wputenv_s
_tremoveremoveremove_wremove
_trenamerenamerename_wrename
_trmdir_rmdir_rmdir_wrmdir
_tsearchenv_searchenv_searchenv_wsearchenv
_tsearchenv_s_searchenv_s_searchenv_s_wsearchenv_s
_tscanfscanfscanfwscanf
_tscanf_sscanf_sscanf_swscanf_s
_tsetlocalesetlocalesetlocale_wsetlocale
_tsopen_sopen_sopen_wsopen
_tsopen_s_sopen_s_sopen_s_wsopen_s
_tspawnl_spawnl_spawnl_wspawnl
_tspawnle_spawnle_spawnle_wspawnle
_tspawnlp_spawnlp_spawnlp_wspawnlp
_tspawnlpe_spawnlpe_spawnlpe_wspawnlpe
_tspawnv_spawnv_spawnv_wspawnv
_tspawnve_spawnve_spawnve_wspawnve
_tspawnvp_spawnvp_spawnvp_wspawnvp
_tspawnvpe_spawnvpe_spawnvpe_wspawnvpe
_tsplitpath_splitpath_splitpath_wsplitpath
_tstat_stat_stat_wstat
_tstat32_stat32_stat32_wstat32
_tstati32_stati32_stati32_wstati32
_tstat64_stat64_stat64_wstat64
_tstati64_stati64_stati64_wstati64
_tstofatofatof_wtof
_tstoiatoiatoi_wtoi
_tstoi64_atoi64_atoi64_wtoi64
_tstolatolatol_wtol
_tstrdate_strdate_strdate_wstrdate
_tstrdate_s_strdate_s_strdate_s_wstrdate_s
_tstrtime_strtime_strtime_wstrtime
_tstrtime_s_strtime_s_strtime_s_wstrtime_s
_tsystemsystemsystem_wsystem
_ttempnam_tempnam_tempnam_wtempnam
_ttmpnamtmpnamtmpnam_wtmpnam
_ttmpnam_stmpnam_stmpnam_s_wtmpnam_s
_ttoiatoiatoi_wtoi
_ttoi64_atoi64_atoi64_wtoi64
_ttolatolatol_wtol
_tunlink_unlink_unlink_wunlink
_tutime_utime_utime_wutime
_tutime32_utime32_utime32_wutime32
_tutime64_utime64_utime64_wutime64
_tWinMainWinMainWinMainwWinMain
_ui64tot_ui64toa_ui64toa_ui64tow
_ui64tot_s_ui64toa_s_ui64toa_s_ui64tow_s
_ultot_ultoa_ultoa_ultow
_ultot_s_ultoa_s_ultoa_s_ultow_s
_ungettcungetcungetcungetwc
_ungettch_ungetch_ungetch_ungetwch
_vftprintfvfprintfvfprintfvfwprintf
_vftprintf_svfprintf_svfprintf_svfwprintf_S
_vsctprintf_vscprintf_vscprintf_vscwprintf
_vsctprintf_s_vscprintf_s_vscprintf_s_vscwprintf_S
_vsntprintf_vsnprintf_vsnprintf_vsnwprintf
_vsntprintf_s_vsnprintf_s_vsnprintf_s_vsnwprintf_s
_vstprintfvsprintfvsprintfvswprintf
_vstprintf_svsprintf_svsprintf_svswprintf_s
_vtprintfvprintfvprintfvwprintf
_vtprintf_svprintf_svprintf_svwprintf_s

  • 2
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值