// 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的更多相关文章

  1. C++_标准模板库STL概念介绍1-建立感性认知

    标准模板库的英文缩写是STL,即Standard Template Library. STL里面有什么呢? 它提供了一组表示容器.迭代器.函数对象和算法的模板. 容器是一个与数组类似的单元,可以存储若 ...

  2. 使用“Cocos引擎”创建的cpp工程如何在VS中调试Cocos2d-x源码

    前段时间Cocos2d-x更新了一个Cocos引擎,这是一个集合源码,IDE,Studio这一家老小的整合包,我们可以使用这个Cocos引擎来创建我们的项目. 在Cocos2d-x被整合到Cocos引 ...

  3. Json CPP 中文支持与入门示例

    在每一个Json Cpp自带*.cpp文件头加上: #include "stdafx.h" 将Json Cpp对自带的头文件的引用修改为单引号方式,例如json_reader.cp ...

  4. cpp 调用python

    在用cpp调用python时, 出现致命错误: no module named site  ,  原因解释器在搜索路径下没有找到python库.可以在调用Py_Initialize前,调用 Py_Se ...

  5. nginx+fastcgi+c/cpp

    参考:http://github.tiankonguse.com/blog/2015/01/19/cgi-nginx-three/ 跟着做了一遍,然后根据记忆写的,不清楚有没错漏步骤,希望多多评论多多 ...

  6. APM程序分析-ArduCopter.cpp

    该文件是APM的主文件. #define SCHED_TASK(func, rate_hz, max_time_micros) SCHED_TASK_CLASS(Copter, &copter ...

  7. APM程序分析-AC_WPNav.cpp

    APM程序分析 主程序在ArduCopter.cpp的loop()函数. /// advance_wp_target_along_track - move target location along ...

  8. Dev Cpp 输出中文字符问题

    最近 c++ 上机作业,vc++6.0 挂了没法用,只好用 Dev Cpp 先顶替一下,然而在遇到输出中文字符的时候出现了乱码的情况,但这种情况又非常诡异.于是简单了解了一下写成此博客. [写在前面] ...

  9. 【安卓】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 ...

  10. Identify Memory Leaks in Visual CPP Applications —— VLD内存泄漏检测工具

    原文地址:http://www.codeproject.com/Articles/1045847/Identify-Memory-Leaks-in-Visual-CPP-Applications 基于 ...

随机推荐

  1. Prometheus监控学习笔记之教程推荐

    最近学习K8S和基于容器的监控,发现了如下的教程质量不错,记录下来以备参考 1. K8S最佳实战(包括了K8S的Prometheus监控和EFK日志搜集) https://jimmysong.io/k ...

  2. linux 安装 ImageMagick 和 imagick 扩展

    使用命令安装 1.依次运行以下命令 yum install ImageMagick yum install ImageMagick-devel yum install php-pear 安装php-p ...

  3. php 把秒数转换为时长(h:i:s格式)

    /** * 把秒数转换为时分秒的格式 * @param Int $times 时间,单位 秒 * @return String */ function secToTime($times){ $resu ...

  4. python简说(八)random

    import randomprint(random.randint(1,23))#随机整数l=[1,2,3,4]s='abcdefeg'print(random.choice(s))#随机选择一个元素 ...

  5. linux下网卡bonding配置(转)

    linux下网卡bonding配置   章节 bonding技术 centos7配置bonding centos6配置bonding 一.bonding技术 bonding(绑定)是一种linux系统 ...

  6. ps -ef|grep详解

    ps命令将某个进程显示出来 grep命令是查找 中间的|是管道命令 是指ps命令与grep同时执行 PS是LINUX下最常用的也是非常强大的进程查看命令 grep命令是查找,是一种强大的文本搜索工具, ...

  7. 推荐 Net C# 逆向反编译四大工具利器

    参考:https://blog.csdn.net/kongwei521/article/details/54927689/

  8. django基础 -- 5. ORM 数据库操作

    一. ORM 对象关系映射 类   ------   表 类对象   ------   记录 类属性   ------   字段 二.  连接数据库配置 1.在  setting.py 文件中重新设置 ...

  9. POJ - 1287 Networking 【最小生成树Kruskal】

    Networking Description You are assigned to design network connections between certain points in a wi ...

  10. Asp.Net 之 js/jquery获取服务器端控件

    由于ASP.NET网页运行后,服务器控件会随机生成客户端id,jquery获取时候不太好操作,总结有以下3种方法:服务器控件代码:<asp:TextBox ID="txtUserID& ...