Boost logo

Boost Users :

Subject: Re: [Boost-users] determining the number of collumns in a .csv file
From: Zachary Turner (divisortheory_at_[hidden])
Date: 2009-07-27 14:18:55


On Mon, Jul 27, 2009 at 6:52 AM, Sean
Farrow<sean.farrow_at_[hidden]> wrote:
> Hi:
>
> I am currently using the boost.spirit example to process a csv file. Rather
> than stuffing all values in to a vector as the example does what I’dx like
> to do is to determine how many columns exist and stuff all values in to a
> multi-dimensional array.
>
> What is the best way of doing this?

Look up boost::tokenizer and escaped_list_separator. This was built
exactly to handle the CSV file format (technically, a superset of
csv). use std::distance to find out how many tokens (columns) were
found (e.g. if you need to pre-allocate your array based on the number
of columns), and then iterate through them using standard methods to
insert each one.


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net