-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstrings.cpp
More file actions
37 lines (32 loc) · 903 Bytes
/
Copy pathstrings.cpp
File metadata and controls
37 lines (32 loc) · 903 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
32
33
34
35
36
37
#include <vector>
#include <iterator>
#include <string>
#include <sstream>
#include <string_view>
#include <iostream>
#include <cstdint>
/* Takes delimiter, returns vector of strings split on that delimiter */
std::vector<std::string> split_string(const std::string& s, char delimiter = ' ') {
std::vector<std::string> tokens;
std::istringstream iss(s);
std::string token;
while(std::getline(iss, token, delimiter)) {
tokens.push_back(token);
}
return tokens;
}
/* Basic print functions */
void print(std::string_view& str) {
std::cout << str << std::endl;
}
void print(const std::string& str) {
std::cout << str << std::endl;
}
void print_vector(const std::vector<std::string> strings) {
for(auto &s: strings) {
print(s);
}
}
uint32_t string_to_int32(const std::string& str) {
return static_cast<uint32_t>(std::stoul(str, nullptr, 0));
}