经常会看到windows程序里在字符串前面加上_T, L, _TEXT等等宏,实际上就是针对16bit unicode和8bit ansi的指示符。_T = TEXT = _TEXT
"8 bit characters"
L("16 bit characters")
_T("generic characters")
Windows根据当前UNICODE是否定义来判断通用的宏对应WCHAR还是CHAR。
#ifdef UNICODE
#define TCHAR WCHAR
#else
#define TCHAR CHAR
#endif
对指向字符串的指针也有通用的宏。
LPTSTR
LPCTSTR (指向常量字符串)
如果要使用这些通用的宏,需要#include <windows.h>与 #include <tchar.h>。当使用Visual Studio 2003.NET创建C++ console工程,会出现_tmain作为入口的程序。而 _t 表示使用对unicode与ansi通用的函数。包含了<tchar.h>的工程,main()与tmain()都可以作为入口函数
#include "stdafx.h"
int _tmain(int argc, _TCHAR* argv[])
{
return 0;
}
"stdafx.h"中则定义了
#pragma once
#include <iostream>
#include <tchar.h>
实际上就是包含了<tchar.h>