[英]C2440 error when using Qt creator but code runs fine using VS2010 Express
I have these lines of code in a command line project in VS2010 c++. 我在VS2010 c ++的命令行项目中有这些代码行。
TCHAR name[30];
LPTSTR pname=&name[0];
std::wstring OutNumber;
pname = &name[0];
GetWindowText(hGameNumber,pname,30);
works fine without problems. 工作正常,没有问题。 No I'm using the same lines in a Qt widget base application using Qt Creator.
不,我在使用Qt Creator的Qt小部件基础应用程序中使用相同的行。 When compiling it I get the error:
编译时出现错误:
"error: C2440: 'initializing' : cannot convert from 'TCHAR *' to 'LPTSTR' Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast" “错误:C2440:'正在初始化':无法从'TCHAR *'转换为'LPTSTR'指向的类型无关;转换需要reinterpret_cast,C样式强制转换或函数样式强制转换”
Thanks for any help, Lumpi 感谢您的帮助,隆比
cast, as in LPTSTR pname = reinterpret_cast<LPTSTR>(&name[0]);
强制转换,如
LPTSTR pname = reinterpret_cast<LPTSTR>(&name[0]);
and all will be well. 一切都会好起来的。 also remove the line that reads
pname = &name[0];
还删除读取
pname = &name[0];
right after you create the std::wstring object. 在创建std :: wstring对象之后。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.