[VC++]CComBSTR数据类型比较

// dd.cpp : 定义控制台应用程序的入口点。
//

#include "stdafx.h"
#include <iostream>
#include <atlbase.h>

using namespace std;


int _tmain(int argc, _TCHAR* argv[])
{
	CComBSTR bVal("1.0");
	if(bVal != L"1.0")
		cout<<"no"<<endl;
	else
		cout<<"yes"<<endl;

	return 0;
}

上面是vc++.net2005上的一个win32控制台程序,在程序运行时,进入了else。

但是上面的代码在vc6中,运行的时候却是进入了if。

这是为什么呢?

因为在vc6中对于CComBSTR没有!=的重载,但是在vc2005中却有它的重载。所以猜测在vc6中比较的可能是地址!

原文地址:https://www.cnblogs.com/joeblackzqq/p/2015479.html