I am having a major problem with a really simple File I/O operation. I have a pretty simple datafile filled with a list of names and courses.
Happy Singing
Dopey Dancing
Sneezy Etiquette
Slimey Math
Grumpy Mining
Slinky Karate
Happy Mining
Dopey Mining
Doc Singing
Doc Math
Doc Medicine
Grumpy Medicine
Sleazy Karate
Stringbean Dancing
Stinky Etiquette
Stinky Dancing
Stinky Math
Silly Minging
Sleepy Karate
Sleazy Mining
Sleepy Dancing
Bashful Dancing
Bashful Singing
Grumpy Etiquette
Stringbean Writing
Dopey Writing
Doc Writing
Bashful Karate
Sneezy Medicine
Sneezy Math
Sneezy SinginG
Stinky Mining
Sloppy Etiquette
Slimy Writing
Sloppy Karate
Sloppy Math
I am trying to read the name and the course into a large MultiLinkedList. However, for some reason the data is getting corrupted between the file reading and then the input into the program. This is what the file reading operation is producing for output when I decided to do a dump of the input into a output during debugging.
happy singing 搀漀瀀攀礀ഀ
dancing 猀渀攀攀稀礀 攀琀椀焀甀攀琀琀攀ഀ
slimey洀愀琀栀 ഀ
grumpy mining 猀氀椀渀欀礀ഀ
karate 栀愀瀀瀀礀 洀椀渀椀渀最ഀ
dopey洀椀渀椀渀最 ഀ
doc singing 搀漀挀ഀ
math 搀漀挀 洀攀搀椀挀椀渀攀ഀ
grumpy洀攀搀椀挀椀渀攀 ഀ
sleazy karate 猀琀爀椀渀最戀攀愀渀ഀ
dancing 猀琀椀渀欀礀 攀琀椀焀甀攀琀琀攀ഀ
stinky搀愀渀挀椀渀最 ഀ
stinky math 猀椀氀氀礀ഀ
minging 猀氀攀攀瀀礀 欀愀爀愀琀攀ഀ
sleazy洀椀渀椀渀最 ഀ
sleepy dancing 戀愀猀栀昀甀氀ഀ
dancing 戀愀猀栀昀甀氀 猀椀渀最椀渀最ഀ
grumpy攀琀椀焀甀攀琀琀攀 ഀ
stringbean writing 搀漀瀀攀礀ഀ
writing 搀漀挀 眀爀椀琀椀渀最ഀ
bashful欀愀爀愀琀攀 ഀ
sneezy medicine 猀渀攀攀稀礀ഀ
math 猀渀攀攀稀礀 猀椀渀最椀渀最ഀ
stinky洀椀渀椀渀最 ഀ
sloppy etiquette 猀氀椀洀礀ഀ
writing 猀氀漀瀀瀀礀 欀愀爀愀琀攀ഀ
sloppy洀愀琀栀 猀氀漀瀀瀀礀ഀ
Obviously this is entirely throwing the data structure completely out whack as it has no way for handling borked input like that. Here is the entire file read operation, it is really simple...
ifstream fin("students.txt");
ofstream fout("students_out.txt");
if(!fin)
{
cout << "[ERR] - Unable to open datafile for read operations. Exiting." << endl;
exit(1);
}
while (!fin.eof())
{
fin >> name;
fin >> course;
strlow(name);
strlow(course);
// DEBUG //
fout << name;
fout << " ";
fout << course;
fout << endl;
// DEBUG //
schedule.insert(name, course);
}
fin.close();
fout.close();
The code for strlow() does not appear to be the problem. But if anyone wants to see it, here it goes:
void strlow(string& value)
{
for (unsigned int i = 0; i < value.length(); ++i)
{
value[i] = tolower(value[i]);
}
}
Any assistance would be appreciated, as this is the last serious bug holding up my project. I know everything else works because I can manually enter all the data from the program. But that's rather useless.