c++ convert from LPCTSTR to const char *(C++ 从 LPCTSTR 转换为 const char *)
问题描述
我在 MSVC2008 MFC 中有这个问题.我正在使用 unicode.我有一个函数原型:
MyFunction(const char *)我称之为:
MyfunFunction(LPCTSTR wChar).<块引用>
错误:无法将参数 1 从LPCTSTR"转换为const char *"
如何解决?
由于您使用的是 MFC,您可以轻松地让 CString 进行从 char 到 TCHAR 的自动转换>:
MyFunction(CString(wChar));无论您的原始字符串是基于 char 还是基于 wchar_t,这都有效.
看来我最初的回答与您所要求的相反.轻松修复:
MyFunction(CStringA(wChar));CStringA 是 CString 的一个版本,它专门包含 char 字符,而不是 TCHAR.还有一个 CStringW 保存 wchar_t.
I have this problem in MSVC2008 MFC. I´m using unicode. I have a function prototype:
MyFunction(const char *)
and I'm calling it:
MyfunFunction(LPCTSTR wChar).
error:Cannot Convert Parameter 1 From 'LPCTSTR' to 'const char *'
How to resolve it?
Since you're using MFC, you can easily let CString do an automatic conversion from char to TCHAR:
MyFunction(CString(wChar));
This works whether your original string is char or wchar_t based.
Edit: It seems my original answer was opposite of what you asked for. Easily fixed:
MyFunction(CStringA(wChar));
CStringA is a version of CString that specifically contains char characters, not TCHAR. There's also a CStringW which holds wchar_t.
这篇关于C++ 从 LPCTSTR 转换为 const char *的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:C++ 从 LPCTSTR 转换为 const char *
基础教程推荐
- 如何在 C++ 中初始化静态常量成员? 2022-01-01
- 如何通过C程序打开命令提示符Cmd 2022-12-09
- 这个宏可以转换成函数吗? 2022-01-01
- 常量变量在标题中不起作用 2021-01-01
- 静态库、静态链接动态库和动态链接动态库的 .lib 文件里面是什么? 2021-01-01
- 在 C++ 中计算滚动/移动平均值 2021-01-01
- C++结构和函数声明。为什么它不能编译? 2022-11-07
- 我有静态或动态 boost 库吗? 2021-01-01
- 如何检查GTK+3.0中的小部件类型? 2022-11-30
- 如何将 std::pair 的排序 std::list 转换为 std::map 2022-01-01
