Parsing A String using a delimiter in C++.

Code :

#include <iostream>
#include <string>

int main()
{
std::string s = "Praneeth>=damera>=neeth>=Damera>=India>=AP>=Hyd>=MKJ";
std::string delimiter = ">=";

size_t pos = 0;
std::string token;
while ((pos = s.find(delimiter)) != std::string::npos) {
    token = s.substr(0, pos);
    std::cout << token << std::endl;
    s.erase(0, pos + delimiter.length());
}
std::cout << s << std::endl;
}

OUTPUT:

Praneeth
damera
neeth
Damera
India
AP
Hyd

MKJ

Comments