先看一段代码:
#include<iostream>
#include<stdlib.h>
#include<string.h>
using namespace std;
int main()
{
const char* a = "hehe";
const char b[]="hehe";
if(a == "hehe")
cout << "a == hehe"<<endl;
if(strcmp(a,"hehe")==0)
cout << "a strcmp hehe"<<endl;
if(b=="hehe")
cout << "b == hehe"<<endl;
if(strcmp(b,"hehe")==0)
cout << "b strcmp hehe"<<endl;
if(a==b)
cout<<"a == b"<<endl;
return 0;
}
运行结果:
a == hehe
a strcmp hehe
b strcmp hehe