随笔分类 - C++
摘要:#include <iostream> using namespace std; int main() { //switch语句 //给一个电影打分 int fen; cout << "清输入一个分数" << endl; cin >>fen; cout <<"你输入的是"<< fen <<"分"<<
阅读全文
摘要:#include <iostream> using namespace std; int main() { //三目运算符 //创建三个变量A B C //A和B比较,将变量大得赋值变量C int a = 10; int b = 20; int c = 0; c = (a > b ? a : b);
阅读全文
摘要:#include <iostream> using namespace std; int main() { //三只小猪秤体重 //先判断A和B谁重 //A重 让A和C比较 //A重 结果时A重 //C重 结果时C重 //B重 让B和C比较 //B重 结果时B重 //C重 结果时C重 int num
阅读全文
摘要:#include <iostream> using namespace std; int main() { //选择结构 单行if语句 //用户输入分数,如果分数大于600,视为考上一本大学,在屏幕上输出 //1.用户输入分数 int scroe = 0; cout << "请输入一个分数:" <<
阅读全文
摘要:#include <iostream> using namespace std; int main() { //选择结构 多条件if语句 //输入一个考试分数,如果大于600分,视为考上一本大学,在屏幕输出 //大于500,视为二本大学,在屏幕输出 //大于400,视为三本大学,在屏幕输出 //小于
阅读全文
摘要:#include <iostream> using namespace std; int main() { //选择结构 多行if语句 //用户输入分数,如果分数大于600,视为考上一本大学,在屏幕上输出, //如果没考上,打印未考上 //用户输入分数 int score = 0; cout <<
阅读全文
摘要:#include <iostream> using namespace std; int main() { //选择结构 单行if语句 //用户输入分数,如果分数大于600,视为考上一本大学,在屏幕上输出 //1.用户输入分数 int scroe = 0; cout << "请输入一个分数:" <<
阅读全文
摘要:#include <iostream> using namespace std; int main() { //逻辑运算符 或 ||,同假为假,其余为真 int a = 10; int b = 10; cout << (a || b) << endl;//结果真 a = 0; b = 10; cou
阅读全文
摘要:#include <iostream> using namespace std; int main() { //逻辑运算符 与 && 同真为真,其余为假 int a = 10; int b = 10; cout << (a&&b)<< endl;//都真 a = 0; b = 10; cout <<
阅读全文
摘要:#include <iostream> using namespace std; int main() { //逻辑运算符!非,真变假,假变真 int a = 10; cout << !a << endl;//在c++中,除了0都为真 cout << !!a << endl; system("pau
阅读全文
摘要:#include <iostream> using namespace std; int main() { //比较运算符 int a = 10; int b = 20; //== cout << (a == b) << endl;//a等于b,结果0 //!= cout << (a != b) <
阅读全文
摘要:#include <iostream> using namespace std; int main() { //赋值运算符; // = int a = 10; a = 100;//赋值 cout << "a=" << a << endl; // += a = 10; a += 2;//a=a+2;
阅读全文
摘要:#include <iostream> using namespace std; int main() { //1.前置递增; int a = 10; ++a;//让变量+1 cout <<"a="<< a << endl; //2.后置递增; int b = 10; b++;//让变量+1 cou
阅读全文
摘要:#include <iostream> using namespace std; int main() { //取模运算,就是求余数,运算符% int a = 10; int b = 3; cout << a % b << endl; int a2 = 10; int b2 = 20; cout <
阅读全文
摘要:#include <iostream> using namespace std; int main() { //加减乘除 int a = 10; int b = 3; cout << a + b << endl; //加 cout << a - b << endl; //减 cout << a *
阅读全文
摘要:#include <iostream> #include <string> using namespace std; int main() { //1.整数 int num1 = 0; cout << "请输入整型变量num1赋值" << endl; cin >> num1; cout << "整型
阅读全文
摘要:#include <iostream> using namespace std; int main() { //1.创建bool类型 bool flag = true; //true代表真 bool flag1 = false; //false代表假 cout <<flag<< endl; //本质
阅读全文
摘要:#include <iostream> #include <string> using namespace std; int main() { //1.C风格字符串 //注意事项char字符串名[] //注意事项等号后面双引号 char str[] = "C语言风格"; cout << str <<
阅读全文
摘要:#include <iostream> using namespace std; int main() { //转义字符 //换行符\n cout << "你好啊\n学生"; //反斜杠\\ cout << "\\" << endl; //水平制表符\t 作用整齐 cout << "aaa\thel
阅读全文
摘要:#include <iostream> using namespace std; int main() { //1.字符型变量创建方式,单引号,引号内只有一个字符 char ch = 'd'; //2.字符型变量所占用内存大小(1个字节) cout << sizeof(char) << endl;
阅读全文

浙公网安备 33010602011771号