views:

267

answers:

1

Hey everyone,

I was wondering if there was a way to read all of the "words" from a line of text.

the line will look like this: R,4567890,Dwyer,Barb,CSCE 423,CSCE 486

Is there a way to use the comma as a delimiter to parse this line into an array or something?

+6  A: 

Yes, use std::getline and stringstreams.

std::string str = "R,4567890,Dwyer,Barb,CSCE 423,CSCE 486";

std::istringstream iss(str);
std::vector<std::string> words;

while (std::getline(iss, str, ','))
  words.push_back(str);
hrnt
Thanks for your answer I implemented something similar but without vectors.
TheGNUGuy