In my program, fin
is an ifstream
object and song
is a string
.
When the program runs, it opens music.txt and reads from the file. I try to read each line with: getline(fin,song);
I've tried all variations of getline
but it keep ignoring the first 10 or so characters of each line before it starts picking up characters. For instance, if the song name is "songsongsongsongsongname," it might only pick up " songname."
Any ideas?
Here's the simplified code:
void Playlist::readFile(ifstream &fin, LinkedList<Playlist> &allPlaylists, LinkedList<Songs*> &library)
{
string song;
fin.open("music.txt");
if(fin.fail())
{
cout << "Input file failed. No saved library or playlist. Begin new myTunes session." << endl << endl;
}
else
{
while(!fin.eof() && flag)
{
getline(fin, song);
cout << song << "YES." << endl;
}
.....}