第三章 3.4.1节练习
来源:互联网 发布:2017年中国经济知乎 编辑:程序博客网 时间:2024/05/18 03:36
练习3.21
请使用迭代器重做3.3.3节的第一个练习。
解答:
这个就略过吧。
练习3.22
修改之前那个输出text第一段程序,首先把text的第一段全部都改成大写形式,然后再输出它。
解答:
transform(text.begin(), text.end(), text.begin(), toupper);
for(auto it = text.cbegin(); it != text.cend() && !it->empty(); ++it)
cout << *it << endl;
练习3.23
编写一段程序,创建一个含有10个整数的vector对象,然后使用迭代器将所有元素的值都变成原来的两倍。输出vector对象的内容,检验程序是否正确。
解答:
#include <iostream>#include <vector>using namespace std;int main(){int num[] = { 1, 3, 4, 43, 4, 354, 5, 3, 2, 4, };vector<int> ivec(num, num + 10);for (auto it = ivec.begin(); it != ivec.end(); ++it){*it *= 2;}for (auto i : ivec){cout << i << endl;}}
0 0
- 第三章 3.4.1节练习
- 第三章 3.3.1节练习 & 3.3.2节练习
- 第三章 3.4.2节练习
- 第三章 3.5.1节练习
- 第三章 上机练习1
- 第三章 3.1节练习 & 3.2.2节练习
- 第三章 3.2.3节练习
- 第三章 3.3.3节练习
- 第三章 3.5.2节练习
- 第三章 3.5.3节练习
- 第三章 3.5.4节练习
- 第三章 3.5.5节练习
- 第三章html上机练习1
- HTML第三章上机练习1
- 第三章练习15
- 第三章课后练习
- 第三章 上机练习
- SQL 第三章 练习
- ios多线程边学边杂记
- zoj 3829 Known Notation (The 2014 ACM-ICPC Asia Mudanjiang Regional Contest K题) 贪心
- Java并发编程笔记(1):初步认识并发、并行、进程、线程
- Activity详解 Intent显式跳转和隐式跳转, 及多个Activity之间传值 总 结
- Android开发中的drawable-(hdpi,mdpi,ldpi)和WVGA,HVGA,QVGA的区别以及联系
- 第三章 3.4.1节练习
- TNS-12535 / ORA-12535 on Connection to Database
- 整数二进制展开后1的个数(《编程珠玑》第九章)
- hadoop2.x.x格式化遇到的问题
- [DS][3-19]Evaluate a postfix expression
- 使用Hadoop流进行MapReduce时出现subprocess failed with code 2 No such file or dictionary时的解决方式
- leetcode - Spiral Matrix II
- 传教士与野人过河问题(二)
- Spring监听器ContextLoaderListener的作用