《c++ primer, 5E》

第91页到第94页,笔记:

1、vector支持的操作。

v.empty()、v.size()、v.push_back(t)、v[n]

2、试图通过下标访问不存在vector元素不会被编译器发现,

而是在运行时产生不可预知的值。

3、确保下标合法的有效手段:尽可能使用范围for

4、vector的小结:vector的初始化、vector支持的操作、vector的遍历与随机访问

遇到的问题:

课后练习:

练习3.16

正确。

并且验证 (10, "hi")和{10 , "hi"}等效,

而{10} 和(10)的效果取决vector元素的类型。

练习3.17

#include<iostream>
using std::cin;
using std::cout;
using std::endl;
#include<vector>
using std::vector;
#include<string>
using std::string;
int main()
{
string word;
vector<string> svec;
while(cin >> word){
svec.push_back(word);
}
for(auto &word: svec){
for(auto &ch: word){
ch = toupper(ch);
}
cout << word << endl;
}
return ;
}

练习3.18

不合法。非法访问。 改为 ivec.push_back(42);

练习3.19

反正最好的是 vector<int> v(10 , 42);

练习3.20

1

#include<iostream>
using std::cin;
using std::cout;
using std::endl;
#include<vector>
using std::vector;
#include<string>
using std::string;
int main()
{
int temp;
vector<int> v;
while(cin >> temp){
v.push_back(temp);
}
//随机访问
for(decltype(v.size()) index = ;
index != v.size()-; ++index)
cout << v[index]+ v[index+] << endl;
return ;
}

2

#include<iostream>
using std::cin;
using std::cout;
using std::endl;
#include<vector>
using std::vector;
#include<string>
using std::string;
int main()
{
int temp;
vector<int> v;
while(cin >> temp){
v.push_back(temp);
}
//随机访问
decltype(v.size()) head = ;
auto tail = v.size()-;
for(;
head <= tail; ++head, --tail){
cout << v[head]+v[tail] << endl;
}
return ;
}

c++第十四天的更多相关文章

  1. 我的MYSQL学习心得(十四) 备份和恢复

    我的MYSQL学习心得(十四) 备份和恢复 我的MYSQL学习心得(一) 简单语法 我的MYSQL学习心得(二) 数据类型宽度 我的MYSQL学习心得(三) 查看字段长度 我的MYSQL学习心得(四) ...

  2. 雅虎(yahoo)前端优化十四条军规

    第一条.尽可能的减少 HTTP 的请求数 (Make Fewer HTTP Requests ) http请求是要开销的,想办法减少请求数自然可以提高网页速度.常用的方法,合并css,js(将一个页面 ...

  3. Bootstrap<基础二十四> 缩略图

    Bootstrap 缩略图.大多数站点都需要在网格中布局图像.视频.文本等.Bootstrap 通过缩略图为此提供了一种简便的方式.使用 Bootstrap 创建缩略图的步骤如下: 在图像周围添加带有 ...

  4. Bootstrap<基础十四> 按钮下拉菜单

    使用 Bootstrap class 向按钮添加下拉菜单.如需向按钮添加下拉菜单,只需要简单地在在一个 .btn-group 中放置按钮和下拉菜单即可.也可以使用 <span class=&qu ...

  5. AngularJs的UI组件ui-Bootstrap分享(十四)——Carousel

    Carousel指令是用于图片轮播的控件,引入ngTouch模块后可以在移动端使用滑动的方式使用轮播控件. <!DOCTYPE html> <html ng-app="ui ...

  6. C#编程总结(十四)dynamic

    http://www.cnblogs.com/yank/p/4177619.html C#编程总结(十四)dynamic 介绍 Visual C# 2010 引入了一个新类型 dynamic. 该类型 ...

  7. 解剖SQLSERVER 第十四篇 Vardecimals 存储格式揭秘(译)

    解剖SQLSERVER 第十四篇    Vardecimals 存储格式揭秘(译) http://improve.dk/how-are-vardecimals-stored/ 在这篇文章,我将深入研究 ...

  8. Senparc.Weixin.MP SDK 微信公众平台开发教程(十四):请求消息去重

    为了确保信息请求消息的到达率,微信服务器在没有及时收到响应消息(ResponseMessage)的情况下,会多次发送同一条请求消息(RequestMessage),包括MsgId等在内的所有文本内容都 ...

  9. linux基础-第十四单元 Linux网络原理及基础设置

    第十四单元 Linux网络原理及基础设置 三种网卡模式图 使用ifconfig命令来维护网络 ifconfig命令的功能 ifconfig命令的用法举例 使用ifup和ifdown命令启动和停止网卡 ...

  10. 无废话ExtJs 入门教程十四[文本编辑器:Editor]

    无废话ExtJs 入门教程十四[文本编辑器:Editor] extjs技术交流,欢迎加群(201926085) ExtJs自带的编辑器没有图片上传的功能,大部分时候能够满足我们的需要. 但有时候这个功 ...

随机推荐

  1. CentOS 6U7分区大于2TB的磁盘以及挂载大于16TB分区磁盘的解决方案

    一.内容介绍1.问题描述1).问题一 CentOS 6.x 在格式化大于16TB的ext4分区时,会提示如下错误: mke2fs 1.41.12 (17-May-2010)mkfs.ext4: Siz ...

  2. FW 常见的性能测试工具有: loadRunner/netperf/httperf/apache_ab/Apache JMeter

    常见的性能测试工具有: loadRunner/netperf/httperf/apache_ab/Apache JMeter , 其中loadRunner属于付费软件,所以在这里不做介绍 netper ...

  3. oracle行转列,列转行

    多行转字符串这个比较简单,用||或concat函数可以实现 SQL Code select concat(id,username) str from app_userselect id||userna ...

  4. 前端 HTML文档 详解

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  5. lua源代码学习(一)lua的c api外围实现

    工作后,整个人已经比較松懈了.尽管一直在看lua的源代码.可是一直是比較零碎的时间,没有系统的整理,所以还是收获不多.由于近期工作也不是非常忙了,就想整理下lua的源代码学习的笔记.加深下印象,并分享 ...

  6. iota 币产生私钥的方法

    iota 币的官网是 iota.org,   iota 的官网推荐的钱包地址是: https://github.com/iotaledger/wallet    iota 币产生私钥是没有什么特殊的要 ...

  7. PHP Warning: preg_match(): JIT compilation failed: no more memory in

    PHP7.3出现如下错误:PHP Warning: preg_match(): JIT compilation failed: no more memory in ... 解决方案: 修改 /usr/ ...

  8. python内置函数大全(分类)

    python内置函数大全 python内建函数 最近一直在看python的document,打算在基础方面重点看一下python的keyword.Build-in Function.Build-in ...

  9. R实现的最小二乘lsfit函数学习

    1.源码 function (x, y, wt = NULL, intercept = TRUE, tolerance = 1e-, yname = NULL) { x <- as.matrix ...

  10. [LeetCode] 38. Count and Say_Easy

    The count-and-say sequence is the sequence of integers with the first five terms as following: 1. 1 ...