I am trying to write song information to a text file but nothing is being written to it. The part where I am trying to write the information to onF is running but the file is blank. BTW the code below is part of a recursive function which is the reason for the first few if statements. Any ideas?
void writeToFile(int artist, int album, int song, int nA, int nAl, int nS)
{
ofstream onF("library.txt");
if(song>=nS)
{
album+=1;
song = 0;
}
if(album>=nAl)
{
artist++;
album = 0;
song = 0;
}
if(artist>=nA)
{
onF.close();
return;
}
if(onF.is_open())
{
onF<<artists[artist].artistName<<'#';
onF<<artists[artist].albums[album].albumName<<'#';
onF<<artists[artist].albums[album].songs[song].songName<<'#';
onF<<artists[artist].albums[album].songs[song].songLength<<endl;
cout<<"RAN"<<endl;
}
else
cout<<"File could not be opened."<<endl;
song++;
int numAlbums = artists[artist].numAlbums;
int numSongs = artists[artist].albums[album].numSongs;
writeToFile(artist, album, song, nA, numAlbums, numSongs);
}
Now that I have that working I am having trouble loading the information from the file. It's loading the song info twice with the second time loading everything but the song title. The loop runs twice:
if(inF)
{
while(!inF.eof())
{
getline(inF, newArtist, '#');
getline(inF, newAlbum, '#');
getline(inF, newSong, '#');
inF>>songLength;
cout<<"CALLED"<<endl;
addSong(newArtist, newAlbum, newSong, songLength, numArtists, 0, 0);
}
inF.close();
if(inF.is_open())
cout<<"FAILED TO CLOSE"<<endl;
}