forked from orazaro/accelerated
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path05-00-split.cpp
35 lines (32 loc) · 848 Bytes
/
05-00-split.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
#include <iostream>
#include <vector>
#include <stdexcept>
#include <cctype>
std::vector<std::string> split(const std::string& s)
{
std::vector<std::string> vec;
std::string::const_iterator i = s.begin();
while(i != s.end())
{
while(i != s.end() && isspace(*i))
++i;
std::string::const_iterator j = i;
while(j != s.end() && !isspace(*j))
++j;
if(j != i) {
std::string token = std::string(i, j);
vec.push_back(token);
i = j;
}
}
return vec;
}
int main() {
std::string s;
while(std::getline(std::cin, s)) {
std::vector<std::string> v = split(s);
for(std::vector<std::string>::size_type i = 0; i != v.size(); ++i)
std::cout << "[" << v[i] << "]" << std::endl;
}
return 0;
}