Hi, I have a readFile() function that reads a csv file into a vector.
The first two lines of the csv are collum headings.
After reading and displaying the file on screen, replacing ","'s with spaces, it asks if the user wants to append new entries. If yes, it calls appendFile() which collects the entries and then calls writeFile() to append to the file.
The problem is, when it first reads existing file, it puts the headings into the vector to, which means it rewrites them when it appends.
So what I want to do is have my readFile() start reading at the third line since if the file exists, it will have headings in the first two lines. I have another function , createFile() Which makes the original file with headings already in it.
Here is my readFile():
void readFile(string)
{
cout << "Type the name of the file.\n";
getline(cin, fileName);
fstream file( fileName.c_str() );
string text;
stringstream parse (stringstream::in | stringstream::out);
while (getline(file, text, ','))
{
parse << text;
data.push_back(text);
data.push_back(" ");
}
for (iter = data.begin(); iter != data.end(); ++iter)
cout << *iter;
char yesNo;
cout << "\n\n";
cout << "Do you want to add another entry to the file?\n";
cin >> yesNo;
if (yesNo == 'y' || yesNo == 'Y')
{
appendToFile(fileName, data);
}
}