// 程序清单16.5_vect1.cpp -- introducing the vector template
#include <iostream>
#include <cstring>
#include <vector>
const int NUM = 5;
int main()
{
using std::vector;
using std::string;
using std::cin;
using std::cout;
using std::endl;
vector<int> ratings(NUM);
vector<string> titles(NUM);
cout << "You will do exactly as told. You will enter\n"
<< NUM << " book titles and your ratings (0-10). \n";
int i;
for (i = 0; i < NUM; i++)
{
cout << "Enter title #" << i + 1 << ": ";
getline(cin, titles[i]);
cout << "Enter your rating (0-10)";
cin >> ratings[i];
cin.get();
}
cout << "Thank you. You entered the following: \n"
<< "Rating\tBook\n";
for (i = 0; i < NUM; i++)
{
cout << ratings[i] << "\t" << titles[i] << endl;
}
cin.get();
return 0;
}
(2011.07.11)程序清单16.5_vect1.cpp -- introducing the vector template
最新推荐文章于 2023-06-05 18:47:38 发布