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

来源:互联网 发布:快牙zapya软件 编辑:程序博客网 时间:2024/04/29 18:36

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

原创粉丝点击