8.3.1. Using an istringstream
An istringstream is often used when we have some work to do on an entire line, and other work to do with individual words within a line.
As one example, assume we have a file that lists people and their associated phone numbers. Some people have only one number, but others have several—a home phone, work phone, cell number, and so on. Our input file might look like the following:
morgan 2015552368 8625550123drew 9735550130lee 6095550132 2015550175 8005550000
Each record in this file starts with a name, which is followed by one or more phone numbers. We’ll start by defining a simple class to represent our input data:
// members are public by default; see § 7.2 (p. 268)struct PersonInfo { string name; vector<string> ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access