1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
|
#include <iostream>
#include <string>
#include <fstream>
#include <sstream>
using namespace std;
struct Quote {
string date;
int stockID;
string expire;
int strike;
char cOrp;
double bid;
double ask;
double price;
};
int main(int argc, char * argv[]) {
fstream in(argv[1]);
if (!in){
cout << "Unable to open " << argv[1] << endl;
}
else
cout << "Processing " << argv[1] << endl;
// String Variables to read input file
string date;
string stockID;
string expire;
string strike;
string cp;
string bid;
string ask;
string price;
// Numeric fields to copy "numeric" string value to actual numeric values
int stockIdInt;
int numStrike;
double numBid;
double numAsk;
double numPrice;
string lineIn;
while(getline(in, lineIn)) {
stringstream linestr(lineIn);
if (getline(linestr, date, ',') &&
getline(linestr, stockID, ',') &&
getline(linestr, expire, ',') &&
getline(linestr, strike, ',') &&
getline(linestr, cp, ',') &&
getline(linestr, bid, ',') &&
getline(linestr, ask, ',') &&
getline(linestr, price, ',')
)
{
istringstream ( stockID ) >> stockIdInt;
istringstream ( strike ) >> numStrike;
istringstream ( bid ) >> numBid;
istringstream ( ask ) >> numAsk;
istringstream ( price ) >> numPrice;
cout << "\ndate:" << date <<endl;
cout << "stockId:"<< stockIdInt << endl;
cout << "expire:"<< expire << endl;
cout << "strike:"<< numStrike << endl;
cout << "cp:"<< cp << endl;
cout << "bid:"<< numBid << endl;
cout << "ask:"<< numAsk << endl;
cout << "price:"<< numPrice << endl;
cout << "price +10 :"<< numPrice +10 << endl;
}
}
}
|