forked from chihyang/CPP_Primer
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPage322_isstream.cpp
More file actions
28 lines (28 loc) · 902 Bytes
/
Copy pathPage322_isstream.cpp
File metadata and controls
28 lines (28 loc) · 902 Bytes
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
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
using std::cin;
using std::istringstream;
using std::string;
using std::vector;
struct PersonInfo {
string name;
vector<string> phones;
};
int main()
{
string line, word; // will hold a line and word from input, respectively
vector<PersonInfo> people; // will hold all the records from the input
// read the input a line at a time until cin hits end-of-file(or another error)
while(getline(cin, line))
{
PersonInfo info; // create an object to hold this record's data
istringstream record(line); // bind record to the line we just read
record >> info.name; // read the name
while(record >> word) // read the phone numbers
info.phones.push_back(word); // and store them
people.push_back(info); // append this record to people
}
return 0;
}