创建两个vector对象,一个用来装int数据,一个用来装string 数据
// Example16_7vect1.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。 // #include#include #include const int NUM = 5; int main() { // std::cout << "Hello World!n"; using std::vector; using std::string; using std::cin; using std::cout; using std::endl; vector ratings(NUM); vector titles(NUM); cout << "You will do exactly as told.You will entern" << 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" << "RatingtBookn"; for (i = 0; i < NUM; i++) { cout << ratings[i] << "t" << titles[i] << endl; } return 0; }



