I took this code for string split here: string split
char sep = ' ';
std::string s="1 This is an exampl";
for(size_t p=0, q=0; p!=s.npos; p=q)
std::cout << s.substr(p+(p!=0), (q=s.find(sep, p+1))-p-(p!=0)) << std::endl;
The code works ok and the output is:
1
This
is
an
exampl
If I change the separator from ' ' to 'e', the output is:
1 This is an
xampl
The 'e' in exampl is lost. How can I split the string using the same code but not losing the letter used as the separator?