因为VS里的很多字符编码都是采用unicode来编码的,为了兼容字符集。微软开发了tchar包,tchar 在unicode下是wchar(双字符),而普通是char。 因为C++支持两种字符串,即常规的ANSI编码和Unicode编码,这样对应的就有了两套字符串字符串处理函数,比如:strlen和wcslen,分别用于处理两种字符串 。微软将这两套字符集及其操作进行了统一,通过条件编译(通过_UNICODE和UNICODE宏)控制实际使用的字符集,这样就有了_T("")这样的字符串,对应的就有了_tcslen这样的函数
。
为了存储这样的通用字符,就有了TCHAR: 当没有定义_UNICODE宏时,TCHAR = char,_tcslen = strlen;当定义了_UNICODE宏时,TCHAR = wchar_t , _tcslen = wcslen 。当我们定义了UNICODE宏,就相当于告诉了编译器:我准备采用UNICODE版本。这个时候,TCHAR就会变成了wchar_t。而未定义UNICODE宏时,TCHAR变成了unsigned char 。这样就可以很好的切换宽窄字符集。tchar可用于双字节字符串,使程序可以用于中日韩等国
语言文字处理、显示。使编程方法简化。
参考资料:http://zhidao.baidu.com/question/318248378.html
分享到:
相关推荐
#include <stdio.h> #include <windows.h> #include <iostream.h> #include <process.h> #define UM_MSG1 WM_USER+1 #define UM_MSG2 WM_USER+2 DWORD WINAPI Thread1(LPVOID para) { DWORD ...
#include <windows.h> #include <windowsx.h> #include "resource.h" #include "MainDlg.h" #include "mmsystem.h" #include "commdlg.h" #include "WINUSER.H" #include <ctime> #include <cstdlib> #include ...
#include <windows.h> #include <math.h> #define ID_TIMER 1 #define NUM 1000 #define STEP 10 #define TWOPI (2 * 3.14159) LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM) ; int WINAPI WinMain ( ...
#include <windows.h> #include <windowsx.h> #include "resource.h" #include "MainDlg.h" BOOL WINAPI Main_Proc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { switch(uMsg) { HANDLE_MSG(hWnd, WM...
#include <windows.h> #include <math.h> #define SIZE 10 POINT point[21],preposition,aimposition; int head,rear,direction,lenght; LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM) ; int ...
#include<Windows.h> #include"resource.h" #include"Node.h" #include<stdlib.h> #include<time.h> TCHAR szAppname[] = TEXT("Snack_eat"); #define SIDE (x_Client/80) #define x_Client 800 #define y_Client ...
代码如下:#include <stdio>#include <windows>#include <wininet> #define MAXSIZE 1024#pragma comment(lib, “Wininet.lib”) void urlopen(_TCHAR*); int _tmain(int argc, _TCHAR* argv[]){ urlopen(_T(...
zlatlcv Links: Git: Blog: zlatlcv is a lightweight C++ library.... Example code: #include <stdio>#include <locale>#include <tchar>#include "zlatlcv.h"// "Welcome": English, Traditional Chinese, J
#include <graphics.h> // 引用图形库头文件 #include <conio.h> #include<time.h> #if 0 int main1() { initgraph(640, 480); MOUSEMSG m; int r;// 创建绘图窗口,大小为 640x480 像素 while (1) { m = ...
#include <windows.h> #define ID_TIMER 1 #define STRMAXLEN 25 //一个显示列的最大长度 #define STRMINLEN 8 //一个显示列的最小长度 LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM) ; typedef struct ...
本文所述实例是从一个Red Hat开源项目里面扒...#include <tchar> #include <crtdbg> #include <windows> #include <time> #include <sys> class CLog { public: ~CLog(); static CLog* get(TCHAR* path = NULL); v
#include <vector> #include <map> #include <string> #include <list> using namespace std; int _tmain(int argc, _TCHAR* argv[]) { printf(“run main”); vector<int> vect ; vect.push_back(1); vect.push_...
#include <stdio.h> int _tmain(int argc, _TCHAR* argv[]) { CvCapture* capture=0; /*初始化一个视频捕获操作。告诉底层的捕获api我想从Capture1.avi中捕获图片, 底层api将检测并选择相应的解码器并做好...
#include "tchar.h" #define MAX_OF_ARRAY 10 int iTemp = 0; int iTimes = 0; //////////////////////////////////////////////////////// //交换数据 void Change(int *a,int *b) { iTemp = *a; ...
#include <iostream> using namespace std; int _tmain(int argc, _TCHAR* argv[]) { Console console; if( false == console.RunProcess("cmd.exe") ) { cout<<"create cmd.exe process fail"<<endl; return...
在编写代码做测试时发现两个大数相乘结果不正确的问题,测试代码如下: #include “stdafx.h”#include<stdlib>#include<time>int _tmain(int argc, _TCHAR* argv[]){ time_t temp1=1345172428000000; time_t temp...
#include<windows.h> //窗口对象的过程处理函数 LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); //Windows应用程序的主函数 int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE, PSTR lpszCmdLine, int ...
#include "stdafx.h" #include<iostream> using namespace std; //计算圆的面积和周长 float circle(float r) { return 2*3.14*r; }//圆的周长 float area(float r) { return 3.14*r*r; }//圆的面积 int _tmain...
#include "stdafx.h" #include "resource.h" #include"windows.h" #include"stdlib.h" #include"string.h" #include"stdio.h" #define MAX_LOADSTRING 100 HINSTANCE hInst; TCHAR szTitle[MAX_LOADSTRING]...
#include <iostream> using namespace std; int checkSystem(void) { typedef struct { CByte a; CWord b; CInt c; } testStruct; if (sizeof(CByte)!=1) { cout<<sizeof(CByte)<<endl; return 0...