2026-02-28 17:05:12 +08:00
|
|
|
|
//
|
|
|
|
|
|
// Created by violet on 2026/2/28.
|
|
|
|
|
|
//
|
2026-03-02 09:34:44 +08:00
|
|
|
|
#include "cstring"
|
|
|
|
|
|
|
2026-02-28 17:05:12 +08:00
|
|
|
|
#include "iostream"
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
|
int main() {
|
|
|
|
|
|
//==相等 !=不等 >大于 <小于 <=小于等于>=大于等于
|
|
|
|
|
|
int num1 =3;
|
|
|
|
|
|
int num2 =4;
|
|
|
|
|
|
bool r1 = (num1!=num2);
|
|
|
|
|
|
cout<<r1<<endl;
|
2026-03-02 09:34:44 +08:00
|
|
|
|
//字符串要用strcmp比较,否则只能比较内存地址
|
|
|
|
|
|
char s1[]="hello";
|
|
|
|
|
|
char *s2 = "hello";
|
|
|
|
|
|
cout<<(strcmp(s1,s2))<<endl;
|
|
|
|
|
|
char s3[] = "a";
|
|
|
|
|
|
char *s4 = "b";
|
|
|
|
|
|
cout<<(strcmp(s4,s3))<<endl;
|
|
|
|
|
|
|
|
|
|
|
|
cout<<"字面量字符串"<<strcmp("a","b")<<endl;
|
|
|
|
|
|
//只要有一个c++风格的字符串,就可以用比较运算符来比较,比较他们的值而不是内存地址
|
|
|
|
|
|
string s5 = "a";//c++风格字符串
|
|
|
|
|
|
string s6 = "a";
|
|
|
|
|
|
cout<<(s5== s6)<<endl;
|
2026-03-02 18:22:06 +08:00
|
|
|
|
cout<<(1==1 && 2==2)<<endl;
|
|
|
|
|
|
cout<<(1==2 && 2==2)<<endl;
|
|
|
|
|
|
cout<<(1==2 || 2==3)<<endl;
|
|
|
|
|
|
cout<<(1==2 || 2==2)<<endl;
|
|
|
|
|
|
bool s123 = 100;
|
|
|
|
|
|
cout<<(s123)<<endl;
|
2026-02-28 17:05:12 +08:00
|
|
|
|
return 0;
|
|
|
|
|
|
}
|