Cast(const)char *到LPCWSTR [英] Cast (const) char * to LPCWSTR

查看:185
本文介绍了Cast(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 everywhere else那么我得到几十个错误使用 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;

这篇关于Cast(const)char *到LPCWSTR的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆