#include<iostream>
#include<string.h>
#include<string>
using namespace std;
int main(){
char a[] = "1235";
char b[] = "123";
if(*a == *b) cout << "yes" << endl;//比较第一个字符 返回yes
else cout << "No" << endl;
if(strcmp(a,b) == 0) cout << "yes" << endl; // 返回No
else cout << "No" << endl;
string s1 = "1134";
string s2 = "113";
if(s1 == s2) cout << "yes" << endl; //结果No,效率低
else cout << "No" << endl;
if(s1.compare(s2) == 0) cout << "yes" << endl; // 返回No
else cout << "No" << endl;
}
结果:
yes
No
No
No
总结:
C/C++字符比较一律用比较函数进行比较。 ==不是出错就是效率低。