-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutility_functions.h
More file actions
31 lines (27 loc) · 921 Bytes
/
Copy pathutility_functions.h
File metadata and controls
31 lines (27 loc) · 921 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
#ifndef UTILITY_FUNCTIONS_
#define UTILITY_FUNCTIONS_
#include<vector>
#include<string>
using namespace std;
//Split a string into a vector of integers,
vector<int> splitStringToIntVect(string s, string delimiters) {
//Indexes on the string
int beg, pos = 0;
//Number that will be read from string
int num;
//Vector of numbers that will be read from string
vector<int> numbers;
//Starting at pos, find first not of delimiters repeatedly until it
//gets to the end
while((beg = s.find_first_not_of(delimiters, pos)) != string::npos) {
//Find the next delimiter
pos = s.find_first_of(delimiters, beg + 1);
//The number will be the substring starting at beg of size
//pos - beg
num = stoi(s.substr(beg, pos - beg));
//Push num to vector
numbers.push_back(num);
}
return numbers;
}
#endif