TCHAR 函数对照表

TCHAR 函数对照表

TCHAR 函数对照表
Generic-Text Routine Mappings
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

_fgettc

fgetc

fgetc

fgetwc

_fgettchar

_fgetchar

_fgetchar

_fgetwchar

_fgetts

fgets

fgets

fgetws

_fputtc

fputc

fputc

fputwc

_fputtchar

_fputchar

_fputchar

_fputwchar

_fputts

fputs

fputs

fputws

_ftprintf

fprintf

fprintf

fwprintf

_ftprintf_s

fprintf_s

fprintf_s

fwprintf_s

_ftscanf

fscanf

fscanf

fwscanf

_ftscanf_s

fscanf_s

fscanf_s

fwscanf_s

_gettc

getc

getc

getwc

_gettch

_getch

_getch

_getwch

_gettchar

getchar

getchar

getwchar

_gettche

_getche

_getche

_getwche

_getts

gets

gets

getws

_getts_s

gets_s

gets_s

getws_s

_istalnum

isalnum

_ismbcalnum

iswalnum

_istalpha

isalpha

_ismbcalpha

iswalpha

_istascii

isascii

isascii

iswascii

_istcntrl

iscntrl

iscntrl

iswcntrl

_istdigit

isdigit

_ismbcdigit

iswdigit

_istgraph

isgraph

_ismbcgraph

iswgraph

_istlead

Always returns false

_ismbblead

Always returns false

_istleadbyte

Always returns false

isleadbyte

Always returns false

_istlegal

Always returns true

_ismbclegal

Always returns true

_istlower

islower

_ismbclower

iswlower

_istprint

isprint

_ismbcprint

iswprint

_istpunct

ispunct

_ismbcpunct

iswpunct

_istspace

isspace

_ismbcspace

iswspace

_istupper

isupper

_ismbcupper

iswupper

_istxdigit

isxdigit

isxdigit

iswxdigit

_itot

_itoa

_itoa

_itow

_itot_s

_itoa_s

_itoa_s

_itow_s

_ltot

_ltoa

_ltoa

_ltow

_ltot_s

_ltoa_s

_ltoa_s

_ltow_s

_puttc

putc

putc

putwc

_puttch

_putch

_putch

_putwch

_puttchar

putchar

putchar

putwchar

_putts

puts

puts

_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

_stprintf

sprintf

sprintf

swprintf

_stprintf_s

sprintf_s

sprintf_s

swprintf_s

_stscanf

sscanf

sscanf

swscanf

_stscanf_s

sscanf_s

sscanf_s

swscanf_s

_taccess

_access

_access

_waccess

_taccess_s

_access_s

_access_s

_waccess_s

_tasctime

asctime

asctime

_wasctime

_tasctime_s

asctime_s

asctime_s

_wasctime_s

_tccmp

Maps to macro or inline function

_mbsncmp

Maps to macro or inline function

_tccpy

Maps to macro or inline function

_mbccpy

Maps to macro or inline function

_tccpy_s

strcpy_s

_mbccpy_s

wcscpy_s

_tchdir

_chdir

_chdir

_wchdir

_tclen

Maps to macro or inline function

_mbclen

Maps 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

_tcscat

strcat

_mbscat

wcscat

_tcscat_s

strcat_s

_mbscat_s

wcscat_s

_tcschr

strchr

_mbschr

wcschr

_tcsclen

strlen

_mbslen

wcslen

_tcsclen_s

strlen_s

_mbslen_s

wcslen_s

_tcscmp

strcmp

_mbscmp

wcscmp

_tcscoll

strcoll

_mbscoll

wcscoll

_tcscpy

strcpy

_mbscpy

wcscpy

_tcscpy_s

strcpy_s

_mbscpy_s

wcscpy_s

_tcscspn

strcspn

_mbscspn

wcscspn

_tcsdec

_strdec

_mbsdec

_wcsdec

_tcsdup

_strdup

_mbsdup

_wcsdup

_tcserror

strerror

strerror

_wcserror

_tcserror_s

strerror_s

strerror_s

_wcserror_s

_tcsftime

strftime

strftime

wcsftime

_tcsicmp

_stricmp

_mbsicmp

_wcsicmp

_tcsicoll

_stricoll

_mbsicoll

_wcsicoll

_tcsinc

_strinc

_mbsinc

_wcsinc

_tcslen

strlen

strlen

wcslen

_tcslen_s

strlen_s

strlen_s

wcslen_s

_tcslwr

_strlwr

_mbslwr

_wcslwr

_tcslwr_s

_strlwr_s

_mbslwr_s

_wcslwr_s

_tcsnbcnt

_strncnt

_mbsnbcnt

_wcsncnt

_tcsncat

strncat

_mbsnbcat

wcsncat

_tcsncat_s

strncat_s

_mbsnbcat_s

wcsncat_s

_tcsnccat

strncat

_mbsncat

wcsncat

_tcsnccmp

strncmp

_mbsncmp

wcsncmp

_tcsnccmp_s

strncmp_s

_mbsncmp_s

wcsncmp_s

_tcsnccoll

_strncoll

_mbsncoll

_wcsncoll

_tcsncmp

strncmp

_mbsnbcmp

wcsncmp

_tcsnccnt

_strncnt

_mbsnccnt

_wcsncnt

_tcsnccpy

strncpy

_mbsncpy

wcsncpy

_tcsnccpy_s

strncpy_s

_mbsncpy_s

wcsncpy_s

_tcsncicmp

_strnicmp

_mbsnicmp

_wcsnicmp

_tcsncicoll

_strnicoll

_mbsnicoll

_wcsnicoll

_tcsncpy

strncpy

_mbsnbcpy

wcsncpy

_tcsncpy_s

strncpy_s

_mbsnbcpy_s

wcsncpy_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

_tcspbrk

strpbrk

_mbspbrk

wcspbrk

_tcsspnp

_strspnp

_mbsspnp

_wcsspnp

_tcsrchr

strrchr

_mbsrchr

wcsrchr

_tcsrev

_strrev

_mbsrev

_wcsrev

_tcsset

_strset

_mbsset

_wcsset

_tcsspn

strspn

_mbsspn

wcsspn

_tcsstr

strstr

_mbsstr

wcsstr

_tcstod

strtod

strtod

wcstod

_tcstoi64

_strtoi64

_strtoi64

_wcstoi64

_tcstok

strtok

_mbstok

wcstok

_tcstok_s

strtok_s

_mbstok_s

wcstok_s

_tcstol

strtol

strtol

wcstol

_tcstoui64

_strtoui64

_strtoui64

_wcstoui64

_tcstoul

strtoul

strtoul

wcstoul

_tcsupr

_strupr

_mbsupr

_wcsupr

_tcsupr_s

_strupr_s

_mbsupr_s

_wcsupr_s

_tcsxfrm

strxfrm

strxfrm

wcsxfrm

_tctime

ctime

ctime

_wctime

_tctime_s

ctime_s

ctime_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

_tfopen

fopen

fopen

_wfopen

_tfopen_s

fopen_s

fopen_s

_wfopen_s

_tfreopen

freopen

freopen

_wfreopen

_tfreopen_s

freopen_s

freopen_s

_wfreopen_s

_tfsopen

_fsopen

_fsopen

_wfsopen

_tfullpath

_fullpath

_fullpath

_wfullpath

_tgetcwd

_getcwd

_getcwd

_wgetcwd

_tgetdcwd

_getdcwd

_getdcwd

_wgetdcwd

_tgetenv

getenv

getenv

_wgetenv

_tgetenv_s

getenv_s

getenv_s

_wgetenv_s

_tmain

main

main

wmain

_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

_totlower

tolower

_mbctolower

towlower

_totupper

toupper

_mbctoupper

towupper

_tperror

perror

perror

_wperror

_tpopen

_popen

_popen

_wpopen

_tprintf

printf

printf

wprintf

_tprintf_s

printf_s

printf_s

wprintf_s

_tputenv

_putenv

_putenv

_wputenv

_tputenv_s

_putenv_s

_putenv_s

_wputenv_s

_tremove

remove

remove

_wremove

_trename

rename

rename

_wrename

_trmdir

_rmdir

_rmdir

_wrmdir

_tsearchenv

_searchenv

_searchenv

_wsearchenv

_tsearchenv_s

_searchenv_s

_searchenv_s

_wsearchenv_s

_tscanf

scanf

scanf

wscanf

_tscanf_s

scanf_s

scanf_s

wscanf_s

_tsetlocale

setlocale

setlocale

_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

_tstof

atof

atof

_wtof

_tstoi

atoi

atoi

_wtoi

_tstoi64

_atoi64

_atoi64

_wtoi64

_tstol

atol

atol

_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

_tsystem

system

system

_wsystem

_ttempnam

_tempnam

_tempnam

_wtempnam

_ttmpnam

tmpnam

tmpnam

_wtmpnam

_ttmpnam_s

tmpnam_s

tmpnam_s

_wtmpnam_s

_ttoi

atoi

atoi

_wtoi

_ttoi64

_atoi64

_atoi64

_wtoi64

_ttol

atol

atol

_wtol

_tunlink

_unlink

_unlink

_wunlink

_tutime

_utime

_utime

_wutime

_tutime32

_utime32

_utime32

_wutime32

_tutime64

_utime64

_utime64

_wutime64

_tWinMain

WinMain

WinMain

wWinMain

_ui64tot

_ui64toa

_ui64toa

_ui64tow

_ui64tot_s

_ui64toa_s

_ui64toa_s

_ui64tow_s

_ultot

_ultoa

_ultoa

_ultow

_ultot_s

_ultoa_s

_ultoa_s

_ultow_s

_ungettc

ungetc

ungetc

ungetwc

_ungettch

_ungetch

_ungetch

_ungetwch

_vftprintf

vfprintf

vfprintf

vfwprintf

_vftprintf_s

vfprintf_s

vfprintf_s

vfwprintf_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

_vstprintf

vsprintf

vsprintf

vswprintf

_vstprintf_s

vsprintf_s

vsprintf_s

vswprintf_s

_vtprintf

vprintf

vprintf

vwprintf

_vtprintf_s

vprintf_s

vprintf_s

vwprintf_s

//z 2014-05-29 16:33:01 L.216'26819 BG57IV3 T2526097782.K.F2562195839[T3,L96,R3,V44]
多字节和宽字节字符串的转换
使用MultiByteToWideChar函数和WideCharToMultiByte函数可以实现多字节宽字节之间的转换。ATL的一个很好的字符串的转换宏:A2W和W2A,使用起来更加简单。
一、MultiByteToWideChar和WideCharToMultiByte函数
#include <string> 
#include <windows.h> 
using namespace std; 
//Converting a WChar string to a Ansi string 
std::string WChar2Ansi(LPCWSTR pwszSrc) 
{ 
         int nLen = WideCharToMultiByte(CP_ACP, 0, pwszSrc, -1, NULL, 0, NULL, NULL); 
         if (nLen<= 0) return std::string(""); 
         char* pszDst = new char[nLen]; 
         if (NULL == pszDst) return std::string(""); 
         WideCharToMultiByte(CP_ACP, 0, pwszSrc, -1, pszDst, nLen, NULL, NULL); 
         pszDst[nLen -1] = 0; 
         std::string strTemp(pszDst); 
         delete [] pszDst; 
         return strTemp; 
}
string ws2s(wstring& inputws) 
{ 
        return WChar2Ansi(inputws.c_str()); 
}
//Converting a Ansi string to WChar string 
std::wstring Ansi2WChar(LPCSTR pszSrc, int nLen) 
{ 
    int nSize = MultiByteToWideChar(CP_ACP, 0, (LPCSTR)pszSrc, nLen, 0, 0); 
    if(nSize <= 0) return NULL; 
         WCHAR *pwszDst = new WCHAR[nSize+1]; 
    if( NULL == pwszDst) return NULL; 
    MultiByteToWideChar(CP_ACP, 0,(LPCSTR)pszSrc, nLen, pwszDst, nSize); 
    pwszDst[nSize] = 0; 
    if( pwszDst[0] == 0xFEFF)                    // skip Oxfeff 
        for(int i = 0; i < nSize; i ++) 
                            pwszDst[i] = pwszDst[i+1]; 
    wstring wcharString(pwszDst); 
         delete pwszDst; 
    return wcharString; 
}
std::wstring s2ws(const string& s) 
{ 
     return Ansi2WChar(s.c_str(),s.size()); 
}
将WChar字符串转换为Ansi字符串

二、MultiByteToWideChar和WideCharToMultiByte函数

std::wstring AsciiToUnicode(const std::string& str)
{
    // 预算-缓冲区中宽字节的长度  
    int unicodeLen = MultiByteToWideChar(CP_ACP, 0, str.c_str(), -1, nullptr, 0);
    // 给指向缓冲区的指针变量分配内存  
    wchar_t *pUnicode = (wchar_t*)malloc(sizeof(wchar_t)*unicodeLen);
    // 开始向缓冲区转换字节  
    MultiByteToWideChar(CP_ACP, 0, str.c_str(), -1, pUnicode, unicodeLen);
    std::wstring ret_str = pUnicode;
    free(pUnicode);
    return ret_str;
}
 
std::string UnicodeToUtf8(const std::wstring& wstr)
{
    // 预算-缓冲区中多字节的长度  
    int ansiiLen = WideCharToMultiByte(CP_UTF8, 0, wstr.c_str(), -1, nullptr, 0, nullptr, nullptr);
    // 给指向缓冲区的指针变量分配内存  
    char *pAssii = (char*)malloc(sizeof(char)*ansiiLen);
    // 开始向缓冲区转换字节  
    WideCharToMultiByte(CP_UTF8, 0, wstr.c_str(), -1, pAssii, ansiiLen, nullptr, nullptr);
    std::string ret_str = pAssii;
    free(pAssii);
    return ret_str;
}
 
//ANSI转UTF8
std::string AsciiToUtf8(const std::string& str)
{
    return UnicodeToUtf8(AsciiToUnicode(str));
}
 
//UTF8转ANSI
std::string Utf8toAscii(const std::string strUTF8)
{
    std::string  strAnsi = "";
    //获取转换为多字节后需要的缓冲区大小,创建多字节缓冲区
    UINT nLen = MultiByteToWideChar(CP_UTF8, NULL, strUTF8.c_str(), -1, NULL, NULL);
    WCHAR *wszBuffer = new WCHAR[nLen + 1];
    nLen = MultiByteToWideChar(CP_UTF8, NULL, strUTF8.c_str(), -1, wszBuffer, nLen);
    wszBuffer[nLen] = 0;
    nLen = WideCharToMultiByte(936, NULL, wszBuffer, -1, NULL, NULL, NULL, NULL);
    CHAR *szBuffer = new CHAR[nLen + 1];
    nLen = WideCharToMultiByte(936, NULL, wszBuffer, -1, szBuffer, nLen, NULL, NULL);
    szBuffer[nLen] = 0;
    strAnsi = szBuffer;
    //清理内存
    delete[]szBuffer;
    delete[]wszBuffer;
    return strAnsi;
}
MultiByteToWideChar和WideCharToMultiByte函数

三、A2W、W2A、A2T、T2A的使用方法
类型T。如果定义了 _UNICODE,则T表示W;如果定义了 _MBCS,则T表示A
头文件包含
#include <atlbase.h>

//(1)A2W的用法
USES_CONVERSION;   // 只需要调用一次,就可以在函数中进行多次转换
CString tmpStr;  
char*LineChar="fdsfdsa";  
const WCHAR * cLineChar = A2W(LineChar);  
tmpStr=cLineChar;  
//获取字符个数
wcslen(cLineChar );

W2A的用法:

USES_CONVERSION;  
CString tmpStr;  
WCH LineChar="fdsfdsa";  
const char* cLineChar = A2W(LineChar);  

A2T的用法:

USES_CONVERSION;  
char * pChar="char to cstring";  
CString cTemp=A2T(pChar);  

T2A的用法:

USES_CONVERSION;  
CString cTemp =_T("char to cstring");  
char * pChar=T2A(cTemp.GetBuffer(cTemp.GetLength())); 
A2W、W2A、A2T、T2A的使用方法

四、几种ANSI和UNICODE的宏定义

L 在字符串前加一个L,如 L”我的字符串” 表示将ANSI字符串转换成unicode的字符串,就是每个字符占用两个字节。

strlen(L”asd”) = 6;

_T宏可以把一个引号引起来的字符串,根据你的环境设置,使得编译器会根据编译目标环境选择合适的(Unicode还是ANSI)字符处理方式。

TEXT,_TEXT 和_T 一样的。

std兼容字符串定义

 

#ifdef _UNICODE  
#define tstring std::wstring  
#else  
#define tstring std::string  
#endif

 

long int strtol(const char *str, char **endptr, int base) 把参数 str 所指向的字符串根据给定的 base 转换为一个长整数(类型为 long int 型),base 必须介于 2 和 36(包含)之间,或者是特殊值 0。

 

实例:

#include <stdio.h>
#include <stdlib.h>
int main()
{
   char str[30] = "2030300 This is test";
   char *ptr;
   long ret;
   ret = strtol(str, &ptr, 10);
   printf("数字(无符号长整数)是 %ld\n", ret);
   printf("字符串部分是 |%s|", ptr);
   return(0);
}

结果:

 

数字(无符号长整数)是 2030300

字符串部分是 | This is test|

 

开源字符转换iconv

http://www.gnu.org/software/libiconv/

https://blog.csdn.net/langresser_king/article/details/7459367

————————————————

版权声明:本文为CSDN博主「byxdaz」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。

原文链接:https://blog.csdn.net/byxdaz/article/details/80507510

posted on 2022-06-04 11:25  悠心不已  阅读(44)  评论(0)    收藏  举报

导航