strcmp 对比两个字符串是否相等 bool
strcmp 对比两个字符串是否相等 bool
c //Strcmp字符比较
判断字符串数组
用 strcmp 判断数组 零相等, 非零不相等
数组直接判断,是判断 地址
a+=b a=a+b
strcmp(字符串1,字符串2)
比较字符串里的字符
0相等 非零 不等
string 字符串1="asd";
string 字符串2="asd";
(字符串1==字符串2)
string类型的字符串可以直接比较
用strcmp来判断两个char风格字符串中字符内容是否相同,返回0则相同。直接比较时比较的是其指针(地址)
string风格字符串可直接比较内容是否相同,返回1则相同
#include <iostream>
using namespace std;
int main()
{
// + - * / %
// += -= *= /= %=
//int a = 23, b = 29;
//a += b; // a = a + b;
//cout << a << endl; // 52
//a -= b;
//cout << a << endl; // 23
//a *= b;
//cout << a << endl; //667
//a /= b;
//cout << a << endl; // 23
//a %= b;
//cout << a << endl; // 23
// > >= < <= == !=
//bool res = 34 > 89;
//cout << res << endl; // 0
//int a = 100, b = 90;
//cout << (a > b) << endl; // 1
//char str1[] = "sikiedu";//"sikiedu2",则1
//char str2[] = "sikiedu";
//cout << (str1 == str2) << endl; // 0 // 笔记:判断的地址
////strcmp(str1, str2); // 0 相等;非0 不等
//cout << strcmp(str1, str2) << endl;
string str1 = "sikiedu";
string str2 = "sikiedu";
cout << (str1 == str2) << endl; // 1
return 0;
}
c语言字符串数组
char 数组【】=“ ”;
c++字符串
string 变量=“ ”;