I will start by saying I am reasonably new as a C++ programmer. However I understand PHP and VBA, so have a good understanding of the aspects of programming fundamentals.
Because I use CSV's quite often in my day to day job, I thought it would be a good learning exercise to write a library that manipulates CSV Files.
I wrote this function:
int getHeaders(ifstream & os, vector<string> & head2){
string STRING;
getline(os,STRING);
cout << STRING << endl;
STRING.erase(remove(STRING.begin(), STRING.end(), '\"'), STRING.end());
string::iterator it = STRING.begin();
int x = 0;
for (int index = 0; it < STRING.end(); it++, index++) {
if (*it == ',') {
head2.push_back(STRING.substr(0,index));
STRING.erase(0,index+1);
cout << endl << head2[x];
cout << endl << STRING;
x++;
}
}
return head2.size();
}
Which is called by the following:
int addRowCount = 0;
vector<string> head1;
ifstream outfile;
outfile.open("default.csv", ios_base::app);
cout << getHeaders(outfile, head1) << endl;
cout << head1[0] << endl << head1[1] << endl;
But when I run the program, the program just dumps a load of random rubbish to the console (and crashes the application) I am using windows so cannot use valgrind.
Does anyone know why this may be happening? Obviously this "dump" is not what I want the application to do. I am hoping someone can point out the part of my code which would make this happen.
Thanks in advance.