C++ 自然语言编码详解系列三(各种编码的统一)

本文详细介绍了C++中处理不同编码问题的策略,特别是TCHAR宏的使用。通过将字符串常量与_T宏结合,以及在定义字符和使用字符串函数时采用TCHAR和_tcs***()函数,可以有效地统一各种编码,避免编码带来的困扰,从而专注于应用程序的上层逻辑开发。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

     存在着的各种编码,在编程实现时,如果不注意会得到不少麻烦;要小心注意的话,又会有点本末倒置

不能专心于上层应用逻辑的开发,是不是就没有办法了?

     就在这时候,TCHAR出现了,说白了就是,用一套宏定义来屏蔽语言间的差别,使用的时候只要以下原则

,则保无忧:

     1. 凡是字符串常量,加_T宏。即 "1232"--> _T("1232");

     2.凡定义字符(串)时,用TCHAR 即 char c ---> TCHAR c;

     3.凡str***()和_mbs***()等字符串函数,用_tcs***()函数代替

         其它的详见下图(总是用最左边的一列函数即可!)

Generic-text
routine name
SBCS (_UNICODE &
MBCS not defined)

_MBCS defined

_UNICODE defined
_cgetts _cgets _cgets _cgetws
_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
_ftscanf fscanf fscanf fwscanf
_gettc getc getc getwc
_gettch _getch _getch _getwch
_gettchar getchar getchar getwchar
_gettche _getche _getche _getwche
_getts gets gets getws
_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
_ltot _ltoa _ltoa _ltow
_puttc
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值