#include <iostream>
#include <vector>
#include <string>
using namespace std;
const int NUM = 5;
int main()
{
vector<string>names(NUM);
vector<int>sexs(NUM);
cout << "Enter " << NUM << " personer name and their sex";
for (int i = 0; i < NUM; i++)
{
cout << "Enter title # " << i + 1 <<": ";
getline(cin, names[i]);
cout << "Enter sex(0/1) # ";
cin >> sexs[i];
cin.get();
}
cout << "You entered the following: " << endl;
for (int i = 0; i < NUM; i++)
{
cout << names[i] << "\t"<< sexs[i] << endl;
}
return 0;
}
c++積累(3):一個vector例子
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.