Leser: 3
10 Einträge, 1 Seite |
QuoteBecause strtok() modifies it's argument, the string is subsequently unsafe and cannot be used in its original form. If you need to preserve the original string, copy it into a buffer and pass the address of the buffer to strtok() instead of the original string.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
std::vector<std::string> StringSplit(const std::string & str, const std::string & pattern) {
std::vector<std::string> retval;
std::string work = str;
int pos;
while((pos = work.find(pattern)) != std::string::npos) {
std::string item = work.substr(0, pos);
retval.push_back(item);
work = work.substr(pos + pattern.length());
}
if(work != "")
retval.push_back(work);
return retval;
}
10 Einträge, 1 Seite |