Reputation: 185
I have the following string :-
CoursesExams = HUM001,Technical Writing,28/4/2016,HallA;CSE121,Computer Programming,3/5/2016,HallB]
I want to split it after each ;
into an array. How can I do that using c++?
Upvotes: 1
Views: 48
Reputation: 49976
Use std::getline and stringstream:
std::string s = "HUM001,Technical Writing,28/4/2016,HallA;CSE121,Computer Programming,3/5/2016,HallB]";
std::vector<std::string> arr;
std::istringstream str(s);
std::string elem;
// getline reads str stream until comma is found, then returns string in elem
while(std::getline(str, elem, ',')) arr.push_back(elem);
for (auto& s : arr) std::cout << s << "\n";
Upvotes: 1