00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035 #include<iostream>
00036 #include"CSV_Obj.h"
00037
00038 using namespace std;
00039
00040 #define EXIT_ERROR 1
00041
00042 void printHeader(CSV_Obj* foo);
00043 void printAllData(CSV_Obj* foo);
00044
00045 int main(int argc, char* argv[]) {
00046
00047 CSV_Obj* foo = new CSV_Obj();
00048 char* filepath;
00049
00050 if(argc > 1) {
00051 filepath = argv[1];
00052 } else {
00053 filepath = "/Users/zednik/data/temperature.csv";
00054 }
00055
00056 if (!foo->open(filepath)) {
00057 cout << "Could not open .CSV file." << endl;
00058 return EXIT_ERROR;
00059 }
00060
00061 foo->load();
00062 printHeader(foo);
00063 printAllData(foo);
00064
00065 delete foo;
00066 return EXIT_SUCCESS;
00067 }
00068
00069 void printAllData(CSV_Obj* foo) {
00070 int count = foo->getRecordCount();
00071 for(int index = 0; index < count; index++) {
00072 string recStr;
00073 vector<string> rec = foo->getRecord(index);
00074 for(vector<string>::iterator it = rec.begin(); it != rec.end(); it++) {
00075 recStr += *it + ", ";
00076 }
00077 recStr = recStr.substr(0, recStr.length() - 2);
00078 cout << recStr << endl;
00079 }
00080 }
00081
00082 void printHeader(CSV_Obj* foo) {
00083 string FL = "Field List: ";
00084 vector<string> fList = foo->getFieldList();
00085 for(vector<string>::iterator it = fList.begin(); it != fList.end(); it++) {
00086 FL += *it + ", ";
00087 }
00088 FL = FL.substr(0, FL.length() - 2);
00089 cout << FL << endl;
00090 }