转自:http://blog.sina.com.cn/s/blog_5038ce7a0100cjb1.html
VC2005、2008编写第一个Windows程序很容易遇到的问题:不能将参数 2(等等吧) 从“const char [ ]”转换为“LPCWSTR”
这是因为VC2005、2008默认定义了#define UNICODE,这样调用的API都是宽字符版本,如同在VC6编程的开头定义了 #define UNICODE……
解决: 1.如果不准备编写使用UNICODE编码的程序,则在工程属性、常规中修改“字符集”选项,默认的“使用UNICODE字符集”导致了上述问题。
2.用VC6使用调用宽字符API的方法转换字符串为宽字符串,即控制台的常用宽字符串前缀L,如"ABC"写成标识定义成宽字符串 L"ABC"。windows编程中使用_T("ABC"),效果是一样的。这样写的程序是UNICODE程序,即使在不同语言计算机上也不会出现乱码……就是程序大小会比ANSI程序大一点点……
转自:http://bbs.youkuaiyun.com/topics/390198228
tchar文件定义 #define __T(x) L ## x L是宽字符串的前缀 __T("你好")展开等价于L“你好”, ##在宏里为连接符比如说:_T("String Text")
展开后就是:L"String Text"
##在宏里面相当于连接符,把前后两个字符串连在一起作为一个字符串。
1,C/C++标准里没有任何解释
2,Rationale 里只解释了为什么用前缀而不是后缀
那么,L 难道就是 Literal 的首字母?或是 Large,或是 Long ?
何不用 Wide ?据说是重用已有的 long 字面量后缀字母?
有没有确切的说法
大家认为是什么
下面是引文
C99
$6.4.5 String literals
$6.4.5/2
A character string literal is a sequence of zero or more multibyte characters enclosed in double-quotes, as in "xyz".A wide string literal is the same, except prefixed by the letter L.
C++2003
$2.13.2 Character literals
$2.13.2/1
A character literal is one or more characters enclosed in single quotes, as in ’x’, optionally preceded by the letter L, as in L’x’.
$2.13.2/2
A character literal that begins with the letter L, such as L’x’, is a wide-character literal. A wide-character literal has type wchar_t.
Rationale for International Standard Programming Languages C
$6.4.5 String literals
An L prefix distinguishes wide string literals. A prefix rather than a suffix notation was adopted so that a translator can know at the start of the processing of a string literal whether it is dealing with ordinary or wide characters.