I am reading from a text file that looks like this:
1|Pink Floyd
2|Genesis
3|Einaudi
4|Melanie C
I have a vector artistVector to store the ID (integer), and the Artist Name char(100).
I am trying to parse the text file and store the parsed ID and Name like this:
artistVector[0] = 1
artistVector[1] = Pink Floyd
artistVector[2] = 2
artistVector[3] = Genesis
artistVector[4] = 4
artistVector[5] = Einaudi
artistVector[6] = 6
artistVector[7] = Melanie C
But for some reason, my code after Pink Floyd is not working with my sqlite insert record function.
static vector<string> readFile(vector<string> artVec, ifstream &iFile) //Read the file into the vector function definition
{
vector<string> vector;
string line;
if (iFile.is_open()) {
while (!iFile.eof()) {
// read an item using | as a delimiter
//getline(artist, line, '|');
getline(iFile, line, '|');
vector.push_back(line);
getline(iFile, line, '\n');
vector.push_back(line);
getline(iFile, line, '\n');
vector.push_back(line);
}
}
else {
cout << "Unable to open file";
}
return vector;
}
int main() {
vector<string> artistVector;
ifstream artistFile("artist.txt"); //Input file
artistVector = readFile(artistVector, artistFile);
std::string sqlArtistInsert[8];
for (int i = 0; i < artistVector.size(); i++) {
sqlArtistInsert[i] = artistVector[i];
}
cout << sqlArtistInsert[0] << endl;
cout << sqlArtistInsert[1] << endl;
cout << sqlArtistInsert[2] << endl;
system("pause");
return 0;
}
My output looks like this:
1
Pink Floyd
2
Notice the white space between Pink Floyd and 2? aka sqlArtistInsert[1] & sqlArtistInsert[2]
please take a look at my code below and any help would be much appreciated!