c++primer 第五版练习答案
c++primer 第五版练习答案
去仗剑天涯
这个作者很懒,什么都没留下…
展开
-
c++ primer第五版6.27 6.28 6.29
#include<iostream> #include<string> using namespace std; int add(initializer_list<int> ls) { int result{0}; for (auto beg = begin(ls); beg != end(ls); beg++) { result += *beg; } return result; } void errmsg(i原创 2020-09-23 22:51:21 · 284 阅读 · 0 评论 -
4.21 4.22
4.21 #include <iostream> #include <string> #include <cctype> #include <vector> using namespace std; int main() { vector<int> ivec = { 1,2,3,4,5,6,7,8,9 }; for (auto iter = ivec.begin(); iter != ivec.end(); ++iter) { *it原创 2020-08-19 11:13:41 · 129 阅读 · 0 评论 -
3.35-3.36
3.35 #include <iostream> #include <string> #include <cctype> #include <vector> using namespace std; int main() { int arr[] = { 1,2,3,4,5,6,7,8,9 }; auto beg = begin(arr), en = end(arr); /*for (auto &c : arr) { c = 0; }*/原创 2020-08-09 09:54:59 · 135 阅读 · 0 评论 -
3.23-3.24
3.23 #include <iostream> #include <vector> using namespace std; int main() { vector<int> ivec{ 1,2,3,4,5,6,7,8,9,10 }; for (vector<int>::iterator it = ivec.begin(); it != ivec.end(); ++it) { *it = *it * 2; cout << *it原创 2020-08-09 09:27:47 · 133 阅读 · 0 评论 -
3.20
#include <iostream> #include <string> #include <cctype> #include <vector> using namespace std; int main() { int i; vector<int> ivec; while (cin >> i) { ivec.push_back(i); } for (vector<int>::size_type is =原创 2020-08-08 01:21:01 · 87 阅读 · 0 评论 -
3.19
1: vector<int> ivec(10,42); vector<int> ivec{42,42,42,42,42,42,42,42,42,42}; vector<int> ivec={42,42,42,42,42,42,42,42,42,42};原创 2020-08-08 00:52:45 · 111 阅读 · 0 评论 -
3.18
不合法;可以改为: vector<int> ivec; ivec.push_back(42);原创 2020-08-08 00:47:37 · 95 阅读 · 0 评论 -
3.17
一种方法:范围for语句: #include <iostream> #include <string> #include <cctype> #include <vector> using namespace std; int main() { string word; vector<string> text; while (cin >> word) { text.push_back(word); } for (auto原创 2020-08-08 00:44:38 · 113 阅读 · 0 评论 -
3.5
把多个字符连接成字符串 #include <iostream> #include <string> using namespace std; int main() { string word,str; while (cin >> word) { str += word; } cout << str << endl; return 0; } 用空格把输入个多个字符串分隔开来 ```cpp #include <原创 2020-08-05 17:07:04 · 88 阅读 · 0 评论 -
3.4
读取两个字符串并输出较大的字符串 #include <iostream> #include <string> using namespace std; int main() { string s1,s2; cout << "Please enter two words!\n"; while (cin >> s1 >> s2) { if (s1 == s2) cout <<"相等 "<< s1 <&l原创 2020-08-05 16:54:57 · 93 阅读 · 0 评论 -
3.3
对于输入运算符(cin)会自动忽略字符前的空白字符,读入字符后再遇到空白字符停止 对于getline函数则会直接读取到换行符就停止,(就算第一个读到换行符也会停止)原创 2020-08-05 16:41:00 · 80 阅读 · 0 评论 -
3.2
一次读入一行,然后输出 #include <iostream> #include <string> using namespace std; int main() { string s; while (getline(cin,s)) cout << s << endl; return 0; } 一次读入一个词,然后输出 #include <iostream> #include <string> using name原创 2020-08-05 16:37:10 · 92 阅读 · 0 评论