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 基于 ...
随机推荐
- 用Java实现MVPtree——MVPtree核心算法代码的搭建
项目需要,需要把MVPtree这种冷门的数据结构写入Java,然网上没有成形的Java实现,虽说C++看惯了不过对C++实现复杂结构也是看得蒙蔽,幸好客户给了个github上job什么的人用Java写 ...
- hibernate 和mybatis
hibernate 和mybatis 你觉得选哪个?原因? Mybatis优势 MyBatis可以进行更为细致的SQL优化,可以减少查询字段. MyBatis容易掌握,而Hibernate门槛较高. ...
- C#.Net环境下的缓存技术
转载:https://www.cnblogs.com/lvjy-net/p/8297679.html 一.缓存技术本节将介绍以下技术: 使用Asp.Net缓存: 使用Remoting Singleto ...
- opencv学习之路(4)、Mat类介绍,基本绘图函数
一.Mat类创建 Mat img;//创建无初始化矩阵 Mat img1(,,CV_8UC1);//200行,100列(长200,宽100) Mat img2(Size(,),CV_8UC3,Scal ...
- Codeforces Round #439 (Div. 2) Problem E (Codeforces 869E) - 暴力 - 随机化 - 二维树状数组 - 差分
Adieu l'ami. Koyomi is helping Oshino, an acquaintance of his, to take care of an open space around ...
- topcoder srm 325 div1
problem1 link $g[i]$表示解决前$i$个的代价,那么$g[i]$是所有$g[j]+cost(j+1,i)$的最小值. import java.util.*; import java. ...
- Delphi XE5 for Android (九)
Delphi XE5 下TEdit控件有个属性:KeyboardType,如下图: 该属性决定了当焦点进入TEdit时,系统弹出的输入窗体,按照其帮助文件说明,不同取值的输入窗体不同,如下图: 根 ...
- POJ 2226 Muddy Fields(最小点覆盖)题解
题意:一片r*c的地,有些地方是泥地,需要铺地板.这些地板宽1,长无限,但只能铺在泥地上不能压到其他地方,问你铺满所有泥地最少几块 思路:我们把一行中连续的泥地看成整体,并把所有横的整体里的点编成一个 ...
- [问题解决]RedHat7更换CentOS7的yum源时踩过的坑
更换yum源的流程 查看当前yum程序 $ rpm -qa|grep yum 这里推荐将其结果截屏或拷贝出来,以免后面报错修复. 删除原有yum源 $ rpm -aq | grep yum|xargs ...
- P3041 [USACO12JAN]视频游戏的连击Video Game Combos
思路 简单的AC自动机上dp,暴力跳fail向子节点直接转移即可 代码 #include <cstdio> #include <algorithm> #include < ...