如何比较BSTR和char * [英] How to compare BSTR with char*

查看:97
本文介绍了如何比较BSTR和char *的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以指导我如何将BSTR变量与const char *进行比较.
我在网上搜索,但没有找到一个好的解决方案.

我确实喜欢这样:-

Can anyone please guide me how to compare BSTR variable with const char*.
I searched net but didn''t found a good solution.

i did like this:-

BSTR var=L"element";

if(var=="a")
{
printf("they are equal\n");//here i get error operands are incompatible i tryed strcmp also
}

推荐答案

BSTR只是指向宽字符串的指针.因此,您必须与宽字符串进行比较,并使用字符串比较功能:
A BSTR is just a pointer to a wide character string. So you must compare with a wide string and use a string compare function:
if (0 == wcscmp(var, L"a"))
    printf("they are equal\n");


if(0== wcscmp(var, L"a"))
  {
printf("they are equal\n")
                       
 }


这篇关于如何比较BSTR和char *的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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