-
Notifications
You must be signed in to change notification settings - Fork 0
/
8.13.cpp
42 lines (39 loc) · 833 Bytes
/
8.13.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include <vector>
#include <string>
#include <sstream>
#include <iostream>
#include <fstream>
using std::ifstream;
using std::cin;
using std::istringstream;
using std::string;
using std::vector;
using std::cout;
using std::endl;
struct PersonInfo {
string name;
vector<string> phones;
};
int main(int argc, char **argv) {
if (argc < 2) return -1;
ifstream inputFile(argv[1]);
if (inputFile.fail()) return -1;
string line, word;
vector<PersonInfo> people;
while (getline(inputFile, line)) {
PersonInfo info;
istringstream record(line);
record >> info.name;
while (record >> word)
info.phones.push_back(word);
people.push_back(info);
}
for (const PersonInfo &elem : people) {
cout << elem.name << " ";
for (const string &phone : elem.phones) {
cout << phone << " ";
}
cout << endl;
}
return 0;
}