The following function will split strings by a certain delimeter:
Headerfile:
#include "Class.h"
#include <string>
#include <vector>
class Class
{
//[...]
public:
//[...]
void StringExplode(std::string str, std::string separator, std::vector<std::string>* results);
};
C++ file:
void Class::StringExplode(string str, string separator, vector<string>* results){
int found;
found = str.find_first_of(separator);
while(found != string::npos){
if(found > 0){
results->push_back(str.substr(0,found));
}
str = str.substr(found+1);
found = str.find_first_of(separator);
}
if(str.length() > 0){
results->push_back(str);
}
}
Example / usage:
printf("line: %sn",lineread.c_str());
// explode line values
vector<string> R;
StringExplode(lineread, " ", &R);
printf("value0: %sn",R[0].c_str());