c++primer第一章:开始

xiaoxiao2021-02-28  114

关于之前不清楚的地方: 1、<<输出运算符,此运算符返回其左侧的运算对象,第一个运算符的结果成为了第二次运算符的左侧对象,>>和<<类似。 2、对于for循环,1、初始化 2、判断 3、执行循环体 4、加1。 3、类机制是C++最重要的特性之一。 4、类的作者定义了类对象可以执行的所有动作。


int main() { //左花括号开始,右花括号结束,语句块 //std::cout << "hello,world" << std::endl; //<<输出运算符,此运算符返回其左侧的运算对象,第一个运算符的结果成为了第二次运算符的左侧对象,>>和<<类似 /*std::cout << std::endl;*/ //cout << "请输入两个数" << endl; /*啊似的发射点*//*不能嵌套*/ //int v1, v2; //cin >> v1 >> v2; //cout << v1 << "和" << v2 << "的积为" << v1*v2 << endl; //cout <</*"*/"/*"/*"*/; /*int sum = 0, val = 0, a = 0, b = 0;*/ /*cin>>a>>b;*/ //while (val <= 10) //{ // sum += val; // a=val++; //后置递增先赋值后加,前置先加后赋值 // /*a=++val;*/ //} //cout << sum; /*if (a >= b)//题1.11 { while (a >= b) { cout << a << endl; a--; } } else { while (a <= b) { cout << a << endl; a++; } }*/ //for (int i = 0; i <= 0; ++i) //1、初始化 2、判断 3、执行循环体 4、加一 //{ //这个地方以前总是不清楚 // sum += i; //} //while (cin >> val) //当时输入是ctrl+z,或者不是数字时结束 //{ // sum += val; //} //cout << sum; /*int currVal = 0, val = 0; //用if语句来统计在输入的每个值连续出现的次数 if (cin >> currVal) { int cnt = 1; while (cin >> val) { if (val == currVal) ++cnt; else { cout << currVal << "occurs" << cnt << "times" << endl; currVal = val; cnt = 1; } } cout << currVal << "occurs" << cnt << "times" << endl; }*/ /*vector<int>a = { 1,1,1,1,2,2,2,2,2 }; int s = a.size(); cout << s << endl; int count = 1; int cur = a[0]; for (int i = 1; i <= s-1; i++) { if (cur == a[i]) { count++; } else { cout << cur << "occurs" << count << endl; cur = a[i]; count = 1; } } cout << cur << "occurs" << count << endl;*/ //在进行之后的实验时要在网上下载头文件,并且不能直接复制到项目中,而是用项目->添加->现有项 /*Sales_item book; cin >> book; cout << book << endl;*/ //Sales_item item1, item2; //1.21 //cin >> item1 >> item2; //if (item1.isbn() == item2.isbn()) //{ // cout << item1 + item2 << endl; // system("pause"); // return 0; //} //else //{ // cout << "error" << endl; // system("pause"); // return -1; //} Sales_item total; if (cin >> total) { Sales_item trans; while (cin >> trans) { if (total.isbn() == trans.isbn()) { total += trans; } else { cout << total << endl; total = trans; } } cout << total << endl; } else { cerr << "NO DATA" << endl; return -1; } /*cout << item1 + item2 << endl;*/ system("pause"); return 0; }
转载请注明原文地址: https://www.6miu.com/read-38057.html

最新回复(0)