Hello,
I am fairly new at C++ and I need to write a program in C++ that opens a csv file, parse the sections into arrays or vectors, and be able to output the arrays or vectors to the screen. This is a large file with over 65k rows.
I want to call the arrays "Cusip", "Time", "Ticker", "Exchange", "Shares", "Price", "Direction", "Code"
The sample data is as follows:
12C51CV12, 20140612 13:30:48.162, BRK/B, NSDQ, 1500, 65.35, SELL, B
All help is needed and appreciated.
//std::ifstream input("some_file_name");
std::string line;
while( std::getline(input, line, '\n') ){
std::stringstream row(std::move(line));
std::string field;
while( std::getline(row>>std::ws, field, ',') ){
//here 'field' has one field (section)
}
}
There every section gets stored in one string, parse that later to create the appropriate type.
You say that you want several arrays, if the data in the row is related perhaps you could have just one array of an struct (that encapsulates and manages such data)
Thank you ne555. How would I do a struct that I can then output each field? I want to be able to sum the 'column' Shares and be able to do calculations such as multiply the 'column' Shares *Price and total that. Thanks
If you are using VS.Net you could try to import excel library then put data in database (MySQL/SQLite) then work dirrectly on these data and then show them with database controls like datagrids.
Else if you are on GCC nor MinGW it could be hardest cause no window classes are present, except, of course, winAPI nor Glade nor GTK, but it need some time to learn it.
After you can do a console interaction but it's not realy user friendly nand developper friendly.
How do I assign each value from the csv file into a column parsed out by the comma?
Then can I output what is in each column to the screen?
Data is as follows in csv file:
12C51CV12, 20140612 13:30:48.162, BRK/B, NSDQ, 1500, 65.35, SELL, B