mirror of
https://github.com/jslightham/cpp-utils.git
synced 2026-03-09 18:12:26 +01:00
21 lines
453 B
C++
21 lines
453 B
C++
#ifndef STRING_H
|
|
#define STRING_H
|
|
#include <sstream>
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
// Split a string on a delimiter to a vector of strings
|
|
inline std::vector<std::string> split(const std::string &str, const char delimiter) {
|
|
std::vector<std::string> result;
|
|
std::stringstream ss(str);
|
|
std::string token;
|
|
|
|
while (std::getline(ss, token, delimiter)) {
|
|
result.push_back(token);
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
#endif //STRING_H
|