I am parsing a string in C++ using the following:
using namespace std;
string parsed,input=\"text to be parsed\";
stringstream input_stringstream(input);
i
A very simple/naive approach:
vector words_seperate(string s){
vector ans;
string w="";
for(auto i:s){
if(i==' '){
ans.push_back(w);
w="";
}
else{
w+=i;
}
}
ans.push_back(w);
return ans;
}
Or you can use boost library split function:
vector result;
boost::split(result, input, boost::is_any_of("\t"));
Or You can try TOKEN or strtok:
char str[] = "DELIMIT-ME-C++";
char *token = strtok(str, "-");
while (token)
{
cout<
Or You can do this:
char split_with=' ';
vector words;
string token;
stringstream ss(our_string);
while(getline(ss , token , split_with)) words.push_back(token);