// I want to read from a file and split each line by comma
// after splitting push those words into a vector and then display vector.
// I tried this code below but did not work as I expected. My text file is
// given under the code.
// My expected output is this
// Hamidur
// Rahman
// MAC
// 125
// MAC
// 190
// MAT
// 231
// Thanks advance.
The getline ( ss, line, ',') reads up to a comma or end-of-stream, whichever comes first. The word after the last comma is a valid read.
The real issue is the way the data is printed from the vector, like Thomas said.
C++11 has a ranged for syntax that is ideal for this purpose.
A traditional loop is okay too, if written correctly.
I did ask you to describe what did happen, because one can usually realize the problem self when trying to tell it to others. That is important part of programming.