/*
cc36a_demo_c++关系操作符和逻辑操作符_逻辑运算符_txwtech
36_CppPrimer_关系操作符和逻辑操作符_逻辑运算符
关系操作符
< ,<=,>,>=,==,!=
逻辑操作符
&&
||
!
特别注意:
短路求值
不能串接关系操作符,0《a<100是错误的
相等测试与bool字面值
*/
/*
cc36a_demo_c++关系操作符和逻辑操作符_逻辑运算符_txwtech
36_CppPrimer_关系操作符和逻辑操作符_逻辑运算符
关系操作符
< ,<=,>,>=,==,!=
逻辑操作符
&&
||
!
特别注意:
短路求值
不能串接关系操作符,0《a<100是错误的
相等测试与bool字面值*/
#include <iostream>using namespace std;int main()
{int a, b;cout << "请输入两个整数: ";cin >> a >> b;if (a == b)cout << a << " 等于 " << b << endl;if (a > b)cout << a << " 大于 " << b << endl;if(a<=b)cout << a << " 小于等于 " << b << endl;if (a != b)cout << a << " 不等于 " << b << endl;if (0 < a &&a < 100)cout << "a>0并且a<100" << endl;elsecout << "a<0或者a>100" << endl;//getchar();//system("pause");return 0;
}
/*
逻辑操作符
*/
#include <iostream>
#include <vector>
#include <string>using namespace std;int main()
{bool a;a = true;//a = false;cout <<"bool a is : " <<a << endl;bool 下雨,上课;下雨 = true;上课 = false;if (下雨 || 上课){cout << "不能外出!" << endl;}下雨 = false;if (!下雨)cout << "可以外出!!!" << endl;if (!下雨 && !上课){cout << "好哩!" << endl;}int x = 0;vector<int> vec; //使用vector容器vec.push_back(6);vec.push_back(9);if (!vec.empty()){x = *vec.begin();//迭代器cout <<"*vec.begin() is: "<< x << endl;}string s("hello");string::iterator it = s.begin();while (it != s.end()){*it = toupper(*it);// toupper变成大写++it;}cout << s << endl;return 0;
}
#include <iostream>//习题5.7
#include <vector>using namespace std;int main()
{int val;vector<int> vec;cin >> val;vec.push_back(val);while (val != 42){cin >> val;vec.push_back(val);}for (vector<int>::const_iterator it = vec.begin(); it != vec.end(); ++it){cout << *it << endl;}while(val!=42)return 0;
}