I have a Visual Studio 2008 C++ project where I would like to be able to take a list of comma-separated values stored in a std::stringstream and put them in a vector like this:
struct Foo
{
std::string A;
std::string B;
std::string C;
}
typedef std::vector< Foo > FooList;
std::stringstream csv; // contains comma separated values
Such that if the stream contained "My,Mother,Eats,\nDonuts,From,Menards", the resulting structure would be:
{ { "My", "Mother", "Eats" },
{ "Donuts", "From", "Menards" } }
What's the best way to accomplish this? I was looking at using boost.split
if there is a way to specify how the string is copied to the vector.
FooList list;
boost::split( list, csv.str(), boost::is_any_of( "," ) );
I have control over the stream data, so if formatting it slightly differently makes things easier, I can do that.