P678-vect2.cpp
// CH1608.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include <string>
#include <vector>
#include <iostream>
using namespace std;
struct Review{
std::string title;
int rating;
};
bool FillReview(Review &rr); //输入Review对象
void ShowReview(const Review &rr); //输出Review对象
int _tmain(int argc, _TCHAR* argv[])
{
vector<Review> books;
Review temp;
while( FillReview(temp) )
books.push_back(temp);
int num=books.size();
if(num>0)
{
cout<<"Thank you ,you entered the following:\n"
<<"Rating\tBook\n";
for(int i=0;i<num;i++)
{
ShowReview(books[i]);
}
cout<<"Reprising:\n"
<<"Rating\tBook\n";
vector<Review>::iterator pr;
for(pr=books.begin();pr!=books.end();pr++)
ShowReview(*pr);
vector <Review>oldlist(books); //copy constructor used
if(num>3)
{
//remove 2 items 移除两项
books.erase(books.begin()+1,books.begin()+3);
cout<<"After erasure:\n";
for(pr=books.begin();pr!=books.end();pr++)
ShowReview(*pr);
//insert 1 items插入一项数据
books.insert(books.begin(),oldlist.begin()+1,oldlist.begin()+2);
cout<<"After insert:\n";
for(pr=books.begin();pr!=books.end();pr++)
ShowReview(*pr);
}
books.swap(oldlist); //交换两个容器的内容
cout<<"swapping oldlist with boos:\n";
for(pr=books.begin();pr!=books.end();pr++)
{
ShowReview(*pr);
}
}//end if(num>0)
else
{
cout<<"Nothing entered,nothing gained.\n";
}
return 0;
}
bool FillReview(Review & rr)
{
cout<<"Enter book title(quit to quit):";
getline(cin,rr.title);
if(rr.title == "quit")
{
return false;
}
cout<<"Enter book rating:";
cin>>rr.rating;
if(!cin)
{
return false;
}
while(cin.get() != '\n')
continue;
return true;
}
void ShowReview(const Review &rr)
{
cout<<rr.rating<<"\t"<<rr.title<<endl;
}
运行效果如下

P678-vect2.cpp的更多相关文章
- C++_标准模板库STL概念介绍1-建立感性认知
标准模板库的英文缩写是STL,即Standard Template Library. STL里面有什么呢? 它提供了一组表示容器.迭代器.函数对象和算法的模板. 容器是一个与数组类似的单元,可以存储若 ...
- 使用“Cocos引擎”创建的cpp工程如何在VS中调试Cocos2d-x源码
前段时间Cocos2d-x更新了一个Cocos引擎,这是一个集合源码,IDE,Studio这一家老小的整合包,我们可以使用这个Cocos引擎来创建我们的项目. 在Cocos2d-x被整合到Cocos引 ...
- Json CPP 中文支持与入门示例
在每一个Json Cpp自带*.cpp文件头加上: #include "stdafx.h" 将Json Cpp对自带的头文件的引用修改为单引号方式,例如json_reader.cp ...
- cpp 调用python
在用cpp调用python时, 出现致命错误: no module named site , 原因解释器在搜索路径下没有找到python库.可以在调用Py_Initialize前,调用 Py_Se ...
- nginx+fastcgi+c/cpp
参考:http://github.tiankonguse.com/blog/2015/01/19/cgi-nginx-three/ 跟着做了一遍,然后根据记忆写的,不清楚有没错漏步骤,希望多多评论多多 ...
- APM程序分析-ArduCopter.cpp
该文件是APM的主文件. #define SCHED_TASK(func, rate_hz, max_time_micros) SCHED_TASK_CLASS(Copter, &copter ...
- APM程序分析-AC_WPNav.cpp
APM程序分析 主程序在ArduCopter.cpp的loop()函数. /// advance_wp_target_along_track - move target location along ...
- Dev Cpp 输出中文字符问题
最近 c++ 上机作业,vc++6.0 挂了没法用,只好用 Dev Cpp 先顶替一下,然而在遇到输出中文字符的时候出现了乱码的情况,但这种情况又非常诡异.于是简单了解了一下写成此博客. [写在前面] ...
- 【安卓】aidl.exe E 10744 10584 io_delegate.cpp:102] Error while creating directories: Invalid argument
这几天在使用.aidl文件的时候eclipse的控制台总是爆出如下提示: aidl.exe E 10744 10584 io_delegate.cpp:102] Error while creatin ...
- Identify Memory Leaks in Visual CPP Applications —— VLD内存泄漏检测工具
原文地址:http://www.codeproject.com/Articles/1045847/Identify-Memory-Leaks-in-Visual-CPP-Applications 基于 ...
随机推荐
- SQL介绍
SQL,即structured query language,结构化查询语言,是一种对关系型数据库中的数据进行管理和操作的语言方法,SQL包括6个部分 DQL:数据查询语言,最常用的为select,其 ...
- centos7.3安装Nginx
首先,如果是阿里云的centos的话,去阿里云管理端为80端口设置一组访问规则,因为阿里云默认是不开的 1. 添加Nginx yum 资源库 rpm -Uvh http://nginx.org/pac ...
- python之块包导入
一.模块 1.什么是模块 常见的场景:一个模块就是一个包含了python定义和声明的文件,文件名就是模块名字加上.py的后缀. 但其实import加载的模块分为四个通用类别: 1 使用python编写 ...
- CCF 推荐国际国内会议及中文核心期刊要目总览
CCF 推荐国际国内会议及<中文核心期刊要目总览> Ref :http://www.ccf.org.cn/xspj/rgzn/ Notes: dblp 是一个好网站,上面有各种主要会议的论 ...
- 《学习OpenCV3》第14章课后习题
1.在一条含有 N 个点的封闭轮廓中,我们可以通过比较每个点与其它点的距离,找出最外层的点.(这个翻译有问题,而且这个问题是实际问题) a.这样一个算法的复杂度是多少? b.怎样用更快的速度完成这个任 ...
- 用uniGUI做B/S下业务系统的产品原型体验
从10月份到重庆工作后,一直忙于工作,感兴趣的几个方面的技术都处于暂停. 一个多月来,按照公司要求在做B/S集中式基卫产品的原型,主要是画原型图,开始是用Axure,弄来弄去感觉功能还是弱了些,尤其是 ...
- C# 给类做事件的一般做法
https://docs.microsoft.com/zh-cn/dotnet/standard/events/how-to-raise-and-consume-events 第一个示例演示如何引发和 ...
- Docker 安装Hadoop HDFS命令行操作
网上拉取Docker模板,使用singlarities/hadoop镜像 [root@localhost /]# docker pull singularities/hadoop 查看: [root@ ...
- java 之 基础加强(一)
常用快捷键: alt + / 代码提示 ctrl + / 单行注释 取消注释 ctrl + shift +/ 多行注释(先选中内容) ctrl + shift +\ 取消注释(先选中内容) ctrl ...
- (zhuan) Evolution Strategies as a Scalable Alternative to Reinforcement Learning
Evolution Strategies as a Scalable Alternative to Reinforcement Learning this blog from: https://blo ...