Cast (const) char * to LPCWSTR(将 (const) char * 转换为 LPCWSTR)
问题描述
我正在尝试使用 WinAPI 中的 FindWindow(),我想向用户询问窗口标题的输入:
I'm trying to use FindWindow() from WinAPI, and I want to ask an input for window's title from the user:
char *input;
cout << "Window title: ";
cin >> input;
相当标准.那么,如何将其转换为 LPCWSTR for FindWindow()?
Pretty standard.
Now then, how do I convert this to LPCWSTR for FindWindow()?
我已经尝试过以下方法:_T(input), TEXT(input), (LPCWSTR)input 但没有一个工作.我也尝试使用 wchar_t 而不是 char,但我在其他任何地方都需要 char,所以使用 wchar_t 而不是 char...
I've already tried the following: _T(input), TEXT(input), (LPCWSTR)input but none of them worked.
I also tried using wchar_t instead of char, but I need char everywhere else so then I get dozens of errors for using wchar_t instead of char...
推荐答案
您可以使用 cin 和 cout 的广泛变体:
You can use the wide variants of cin and cout:
wchar_t input[256]; // don't really use a fixed size buffer!
wcout << L"Window title: ";
wcin >> input;
这篇关于将 (const) char * 转换为 LPCWSTR的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:将 (const) char * 转换为 LPCWSTR
基础教程推荐
- GDB 显示调用堆栈上函数地址的当前编译二进制文 2022-09-05
- 如果我为无符号变量分配负值会发生什么? 2022-01-01
- 非静态 const 成员,不能使用默认赋值运算符 2022-10-09
- 为什么派生模板类不能访问基模板类的标识符? 2021-01-01
- 为什么 typeid.name() 使用 GCC 返回奇怪的字符以及如 2022-09-16
- 为什么 RegOpenKeyEx() 在 Vista 64 位上返回错误代码 2021-01-01
- CString 到 char* 2021-01-01
- 通过引用传递 C++ 迭代器有什么问题? 2022-01-01
- 初始化列表*参数*评估顺序 2021-01-01
- 我应该对 C++ 中的成员变量和函数参数使用相同的名称吗? 2021-01-01
