Programming/JAVA, C++, Go, Rust
C++ string split
Roiei
2023. 1. 27. 16:21
반응형
In the C++, we can split a string with a delimiter as follows.
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
std::vector<std::string> splitString(const std::string &input, char delimiter) {
std::vector<std::string> res;
std::stringstream ss(input);
std::string temp;
while (getline(ss, temp, delimiter)) {
res.push_back(temp);
}
return res;
}
and we can use the helper function above like this.
auto listOfInputSrc = splitString(request->input.source, ',');
for (const auto &inputSrc : listOfInputSrc) {
...
}
반응형