A bit of string parsing in C++

  • Thread starter Thread starter tagoma
  • Start date Start date
Joined
10/22/11
Messages
66
Points
18
Say I want to parse a bunch of std::string.

I am opened to:
- C++11
- Boost
- Regex


Code:
// Ed_at_QN.cpp
//
// Powered by the QN Team Spirit
//
 
#include <string>
#include <vector>
#include <iostream>
// other system includes when required
 
int main()
{
    // The data to be parsed
    // YYYY-MM-DD,Date,Open,High,Low,Close,Volume,Adj.Close
    std::vector<std::string> vStrings;
    vStrings.push_back("2013-02-01,54.87,55.20,54.67,54.92,2347600,54.92");
    vStrings.push_back("2013-01-31,54.74,54.97,53.99,54.29,3343300,54.29");
    vStrings.push_back("2013-01-30,54.84,55.35,54.68,54.68,2472800,54.68");
 
    /* Do all that is needed for outputting to the console the following table:
 
    | Date              Adj.Close
    -----------------------------
    | 02/01/2013        54.92
    | 01/31/2013        54.29
    | 01/30/2013        54.68
 
    */
 
    return 0;
}


What are your suggestions?
 
Nice post, Edouard. This is a problem that occurs over and over again.

The Boost has String Algo and Tokenizer libraries.

What maybe useful for QN members is that this parsing can be done in a few lines of code.
 
Here are the specifications of the problem from Edouard and Daniel.

Could be a good QN competition to find the 'best' solution.

BTW we have a solution, maybe others' are better.

Andy
 

Attachments

Back
Top Bottom