比较 2 个 wchar_t 数组
我确信这非常简单,但我来自 c# 背景,其中字符串很简单,现在我正在进入非托管世界,我很困惑。
本质上,我使用 EnumDisplayDevices 来列出可用的设备,我想要定位特定的适配器,因此我需要将 DeviceString 和 DeviceName 与一些已知值进行比较,以查看我是否有合适的适配器可以使用。
但我很困惑,我这样定义了已知值...
wchar_t devName[] = L"Intel(R) HD Graphics Family";
但直接比较不起作用 - if(devName == theDisplay.DeviceName)
strcmp
似乎不起作用使用宽字符,所以我不知道该怎么做,有人知道该怎么做吗?
谢谢
I'm sure this is sooo simple but I've come from a c# background where strings are easy and now I am making a small trip into the unmanaged world I am very confused.
Essentially I am using EnumDisplayDevices to list the available devices, I want to target a particular adapter so I need to compare DeviceString and DeviceName against some know values to see whether or not I have the right adapter to work on.
But I am stumped, I defined the known value as such...
wchar_t devName[] = L"Intel(R) HD Graphics Family";
but direct comparison doesn't work - if(devName == theDisplay.DeviceName)
strcmp
doesnt seem to work with wide chars so I have no idea what to do, anyone know how to do this please?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用
std::wstring
,它有一个operator==
。Use a
std::wstring
, it has anoperator==
.如果您查看 Visual Studio 的
strcmp
帮助,您会发现它列出了 3 个用于比较字符串的函数:strcmp
、wcscmp
和_mbscmp
。您要找的是wcscmp
。If you check Visual Studio help for
strcmp
, you'll find it lists 3 functions to compare strings:strcmp
,wcscmp
and_mbscmp
. The one you're looking for iswcscmp
.