Skip to content

Instantly share code, notes, and snippets.

@ohmiyaji
Created March 13, 2018 15:15
Show Gist options
  • Save ohmiyaji/68cc1374387e21fd3189acbd4a4084e1 to your computer and use it in GitHub Desktop.
Save ohmiyaji/68cc1374387e21fd3189acbd4a4084e1 to your computer and use it in GitHub Desktop.
vector.cpp
#include <iostream>
#include <string>
#include <vector>
using namespace std;
class Hito{
string name;
string phone;
public:
void SetName (string n){ name = n; }
string GetName() const { return name; }
void SetPhone(string p) { phone = p; }
string GetPhone() const { return phone; }
};
int main(){
string s;
Hito h;
vector<Hito> data;
while(1){
cout << "氏名を入力(xxxで終了): ";
cin >> s;
if( s == "xxx") break;
h.SetName(s);
cout << "電話番号を入力:";
cin >> s;
h.SetPhone(s);
data.push_back(h);
}
cout << endl;
cout << "全員のデータを出力します。" << endl;
cout << "全部で" << data.size() << "人" << endl;
cout << "ーーーーー" << endl;
for(vector<Hito>::size_type i=0; i<data.size(); i++){
cout << data[i].GetName() << endl;
cout << data[i].GetPhone() << endl;
cout << "ーーーーー" << endl;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment