1

I would like to parse Yahoo financial csv files in C++. Given that each line is formatted as:

Date,Open,High,Low,Close,Volume,Adj Close  

what is an efficient way to get these values? I would like to store the date into a structure that contains a ctime struct for the date, and doubles for all other values.

Bob
  • 10,741
  • 27
  • 89
  • 143

2 Answers2

2

You could define a struct for line, for example:

struct Instrument
{
   ctime   date_;
   double  open_;
   double  high_;
   double  low_;
   double  close_;
   double  volume_;
   double  adj_;
   double  close_;
};

Then you getline to read each line from file, parse each line(use boost tokenizer, regex or split-a-c++-string) into an Instrument object, then you could store it in a STL container, for example:

std::vector<Instrument> instruments;
instruments.push_back(instrument);
Community
  • 1
  • 1
billz
  • 44,644
  • 9
  • 83
  • 100
0

I think Boost Regular expressions can help you.

http://www.boost.org/doc/libs/1_52_0/libs/regex/doc/html/index.html

Yigang Wu
  • 3,596
  • 5
  • 40
  • 54