// 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. 忘记MySQL root密码,如何不重启修改

    说个前提:mysqld可以处理kill命令发送的信号,如SIGHUP.SIGTERM,SIGHUP信号产生的行为类似于flush命令. 不重启找回root密码首先需要有个较低权限的账号,比如可以修改t ...

  2. js 解密 16进制转10进制,再取ascii码的对应值

    如:\x64 对应 16进制 0x64 转10进制就是 0x64.toString(10) == 100, 查对应的ascii码表得到 ‘d' <div id=code style='displ ...

  3. TCP/IP 最常见的错误原因码 (errno)列表

    对于在基于 UNIX 的环境中的 TCP/IP 用户,下表列出了某些最常见的错误原因码 (errno).它不是完整的错误列表.可以在文件 /usr/include/sys/errno.h 中找到 Er ...

  4. jQuery知识总结(转)

    原文:http://fwhyy.com/2013/04/jquery-knowledge-summary/ 这篇文章在于筛选器的简单例子,让人一看就懂代码的作用 20170223 前言 jQuery一 ...

  5. win7 下安装使用 nginx 出现500错误

    配置虚拟主机域名后访问网站出现500错误,发现是因为路径的反斜杠问题,改成正斜杠后问题解决.

  6. Bugku-CTF之web2-听说聪明的人都能找到答案

    Day1   听说聪明的人都能找到答案   http://123.206.87.240:8002/yanzhengma/  

  7. 前缀和与差分之IncDec sequence

    参考链接:https://blog.csdn.net/hzk_cpp/article/details/80407014 题目链接:https://www.acwing.com/problem/cont ...

  8. SVM学习笔记4-核函数和离群点的处理

    核函数在svm里,核函数是这样定义的.核函数是一个n*n(样本个数)的矩阵,其中:$K_{ij}=exp(-\frac{||x^{(i)}-x^{(j)}||^{2}}{2\sigma ^{2}})$ ...

  9. Bootstrap3基础 img-rounded 图片的四个角改成圆角

      内容 参数   OS   Windows 10 x64   browser   Firefox 65.0.2   framework     Bootstrap 3.3.7   editor    ...

  10. 用vim + xdebug 来追踪thinkphp的执行过程

    tree命令的使用几个有实际应用的参数 -a 这是默认的 -d: 只显式目录, 不需要显式目录下的文件 -L: 列出显式的深度. 当前目录下的所有东西为第一级... 在tp下, 有多个Common但是 ...