- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstrtok.cpp
More file actions
Latest commit
23 lines (19 loc) · 487 Bytes
/
Copy pathstrtok.cpp
File metadata and controls
23 lines (19 loc) · 487 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
/*
Split string with delimiters, similar to strtok
Will not return empty strings
https://ideone.com/LJota9
*/
#include<iostream>
#include<string>
intmain()
{
std::string str = "Hello, everyone! This is: COSC-1436, SP18";
std::string const delims{ " .,:;!?" };
size_t beg, pos = 0;
while ((beg = str.find_first_not_of(delims, pos)) != std::string::npos)
{
pos = str.find_first_of(delims, beg + 1);
std::cout << str.substr(beg, pos - beg) << std::endl;
}
return0;
}