1 // 22-组合赋值运算符和关系运算符.cpp: 定义控制台应用程序的入口点。
2 //
3
4 #include "stdafx.h"
5 #include <iostream>
6 #include <climits>
7 #include <array>
8 #include <string>
9 using namespace std;
10
11 int main()
12 {
13 // + - * /
14 //+= -= *= /= %= 组合赋值运算符
15 int a = 23,b = 29;
16 a += b; //a=a+b;
17 cout << a << endl;
18 a -= b;
19 cout << a << endl;
20 a*=b;
21 cout << a << endl;
22 a /= b;
23 cout << a << endl;
24 a %= b;
25 cout << a << endl;
26
27 //> >= < <= == != 关系运算符
28 bool res = 34 > 89;
29 cout << res << endl;
30 int e = 100, f= 90;
31 cout << (e > f) << endl;
32
33 //字符串比较
34 char str1[] = "uimodel";
35 char str2[] = "uimode1";
36 cout << (str1 == str2)<<endl; //数组本身就是指针,在不同的地址中,默认比较的是地址,所以值不相等,0是false。
37 //如果判断字符串(指针)地址中的数据是否相同呢?
38 strcmp(str1, str2); //比较的就是字符串地址中的值,0相等 非零 不等
39 cout << strcmp(str1, str2) << endl; //如果是比较C语言风格字符串,就需要使用strcmp这的函数进行比较。
40
41 //C++风格的字符串直接比较就行
42 string str3 = "uimodel1";
43 string str4 = "uimodel2";
44 cout << (str3 == str4) << endl; //false,输出结果是0。
45
46 int t;
47 cin >> t;
48 return 0;
49 }