C++ Primer 学习笔记 ——语句
来源:互联网 发布:离线整个知乎 编辑:程序博客网 时间:2024/05/21 04:41
//p164#include<iostream>#include<string>using std::string;using std::cin;using std::cout;int main(){ char i; int count_vowel=0; int count_blank = 0, count_t = 0, count_n = 0, count_ff = 0; while ((i = getchar() )!= EOF)//用cin读入时候,i的类型是什么、?????????? { switch(i) { case 'a':case 'A': case 'e':case 'i': case 'o':case 'u': count_vowel++; break; case '\n':count_n++; break; case '\t':count_t++; break; case' ':count_blank++; break; case'ff':count_ff++;//无法统计2个字符的。???????? default:break; } } cout << count_vowel << " " << count_blank << " " << count_n << " " << count_t << " " << count_ff; return 0;}
//5.4.1#include<iostream>#include<string>#include<vector>using std::string;using std::vector;using std::cout;using std::cin;using std::endl;int main(){ vector<string> vstring; string word, next; cin >> word; vstring.push_back(word); next = word; int count = 1; while (cin >> word) { vstring.push_back(word); if (word == next) count++; else { cout<<next<<":" << count<<endl; count = 1; } next = word; } return 0;}//#include<iostream>//#include<string>//#include<vector>//using std::string;//using std::cin;//using std::vector;//using std::cout;//int main()//{// vector<string> v;// string i;// int count;// while (cin >> i)// v.push_back(i);// for (auto c : v)// cout << c << std::endl;// for (int index = 1; index != v.size()-1; index++)// {// while (v[index - 1] == v[index] && index != v.size()-1 )//v[index - 1]为何不行???????// {// count++;// index++;// }// cout << count;// count = 0;// }// int index = 0;// /*if (v[index] == v[index - 1])// cout << v[index];*/// cout << v[index+1];// return 0;//}
//5.17#include<iostream>#include<vector>using std::vector;using std::cout;using std::endl;int main(){ vector<int> v1{ 0, 1, 1, 2 }, v2{ 0, 1, 1, 2, 3, 5, 8 }; for (int index = 0; index < v1.size() && index < v2.size(); index++) { if (v1[index] != v2[index]) cout << false; } cout << true; return 0;}
//5.19#include<iostream>#include<string>using std::cout;using std::cin;int main(){ std::string st1, st2; do { std::cin >> st1 >> st2; cout<<(st1 < st2 ? st1 : st2); } while (cin); return 0;}
break
负责终止离他最近的while,do while ,for ,swith;
//5.5.1#include<iostream>#include<string>using std::string;using std::cout;using std::cin;int main(){ string st,last; cin >> st; last = st; int flag = 0; while (cin >> st) { if (st == last) { cout << st; flag = 1; break; } last = st; } if (!flag) cout << "none"; return 0;}
goto
goto lable;
try和异常处理
//5.6.3#include<iostream>#include<stdexcept>using std::cin;using std::cout;int main(){ int a, b; /*cin >> a >> b;*/ //if (b == 0) // throw "error"; while (cin >> a >> b) { try{ if (b == 0) throw "error"; } catch (const char*) { cout << "error and try again"; continue; } cout << a / b; } cout << a / b; return 0;}
0 0
- C++ Primer 学习笔记 ——语句
- c++Primer学习笔记(5)--语句
- c++primer学习笔记(6.0)语句
- C++Primer学习笔记(6)语句
- C++primer学习笔记-第六章语句
- C++primer学习笔记-----5.3条件语句
- C++Primer第五版【学习笔记】——第五章 语句
- 《C++ Primer》学习笔记——第五章语句
- C++ Primer学习笔记——$7 语句和函数
- C++ Primer 学习笔记(五)——语句
- C++primer 阅读笔记----------语句
- C++Primer学习笔记第六章(6/18)语句
- c++primer学习笔记4 - 表达式和语句
- 《C++Primer 5e》学习笔记(4):语句
- C++primer学习笔记-----6.3返回类型和return 语句
- C++PRIMER学习笔记
- c++primer学习笔记
- c++primer学习笔记
- OpenGL: 填充非凸多边形 (转)
- 为何 YunOS 有别于 Android?
- URl 传参
- swift post请求参数类型为json
- 动画卡顿之路
- C++ Primer 学习笔记 ——语句
- 数据库水平切分的实现原理解析---分库,分表,主从,集群,负载均衡器(转)
- LeetCode 31 Next Permutation(下一个排列)
- Git移除敏感数据
- OpenGL绘制填充非凸边形
- 多管齐下、与时俱进,唯品会再创佳绩
- HTML5新增标签2,视频,音频,调节颜色
- Java基础(15):集合
- linux /centos 中OpenSSL升级方法详解