程序有点长,,编译无错误,主要是在红色字处要进行cin输入时,
#include <iostream>
#include <set>
#include <vector>
#include <string>
using namespace std;
void readBook()
{
vector<string> bookVec;
set<string> readSet;
readSet.insert("ThinkinginC++");
readSet.insert("C++program");
string bookName;
cout<<"电脑前的这位大狭,请输入您在未来六个月想读的书"<<endl;
while(cin>>bookName)
{
if(!readSet.count(bookName))
{
bookVec.push_back(bookName);
readSet.insert(bookName);
}
else
cout<<"这本书您已经读过了"<<endl;
}
cout<<"六个月后......"<<endl;
vector<string>::iterator iter = bookVec.begin();
while(iter != bookVec.end())
{
cout<<*iter<<" "<<"这本书您读了吗,如果读了请输入Y,如果没有请输入N :";
char ch;
cin>>ch;
if(ch == 'N')
readSet.erase(*iter);
else
;
iter++;
}
cout<<"经过您的确认,您这六个月读的书有"<<bookVec.size()<<"本,分别是:"<<endl;
set<string>::const_iterator set_it = readSet.begin();
while(set_it != readSet.end())
{
cout<<*set_it<<endl;
set_it++;
}
cout<<"您没有读的书有:"<<endl;
iter = bookVec.begin();
while(iter != bookVec.end())
{
if(!readSet.count(*iter))
cout<<*iter;
else
;
iter++;
}
cout<<"程序操作完毕"<<endl;
}
int main()
{
readBook();
system("pause");
return 0;
}
不知道怎么写注释