- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstreams2.cpp
More file actions
Latest commit
31 lines (25 loc) · 623 Bytes
/
Copy pathstreams2.cpp
File metadata and controls
31 lines (25 loc) · 623 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
29
30
31
/*
Fun with streams (part 2)
Reading whole lines and passing them to vector constructor
https://ideone.com/rbyozD
*/
#include<iostream>
#include<sstream>
#include<vector>
#include<string>
#include<iterator>
classline : publicstd::string {};
std::istream &operator >>(std::istream &iss, line &line)
{
std::getline(iss, line, '\n');
return iss;
}
intmain()
{
std::istringstream iss("This is line 1\nThis is line 2\nThis is line 3");
std::vector<std::string> v(std::istream_iterator<line>{iss}, std::istream_iterator<line>{});
// test
for (autoconst &s : v)
std::cout << s << std::endl;
return0;
}