C++ string split
2023. 1. 27. 16:21ㆍProgramming/JAVA, C++, Go, Rust
- 목차
반응형
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) {
...
}
반응형
'Programming > JAVA, C++, Go, Rust' 카테고리의 다른 글
미래지향적인 C++ 프로그래밍 (0) | 2023.01.29 |
---|---|
C++ 헤더 내 구현 장/단점 (0) | 2023.01.27 |
Dynamic Loading DSO (Dynamic Shared Object) (0) | 2023.01.26 |
dlopen, floating point exception (0) | 2023.01.25 |
unordered_map vs. map (0) | 2023.01.25 |