mirror of
http://106.12.3.193:3000/violeteverisland/learn_cpp.git
synced 2026-03-08 01:27:33 +08:00
12
This commit is contained in:
15
比较运算符.cpp
15
比较运算符.cpp
@@ -1,6 +1,8 @@
|
||||
//
|
||||
// Created by violet on 2026/2/28.
|
||||
//
|
||||
#include "cstring"
|
||||
|
||||
#include "iostream"
|
||||
using namespace std;
|
||||
int main() {
|
||||
@@ -9,5 +11,18 @@ int main() {
|
||||
int num2 =4;
|
||||
bool r1 = (num1!=num2);
|
||||
cout<<r1<<endl;
|
||||
//字符串要用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;
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user