xxxxxxxxxx
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
int main()
{
string str="23 156 1645 -2398 77";
vector<string> words;
char delimeter=' ';
int n=str.size();
for(int i=0;i<n;i++)
{
int j=i;
while(str[i]!=delimeter && i<n)
i++;
string temp=str.substr(j,i-j);
words.push_back(temp);
}
return 0;
}
xxxxxxxxxx
#include <string.h>
int main ()
{
char str[] ="This is a sample string";
char *p;
p=strtok(str," ");
while (p!= NULL)
{
cout<<p;
p=strtok(NULL," ");
}
return 0;
}
xxxxxxxxxx
#include <boost/algorithm/string.hpp>
std::string text = "Let me split this into words";
std::vector<std::string> results;
boost::split(results, text, [](char c){return c == ' ';});