I'm having a bit of a formatting error. I've written a program that reads in from file or keyboard and prints out to a new file. Unfortunately I'm getting a blank entry before the proper stuff prints, with normal strings like "," or endls being printed but not the actual interesting stuff. Not sure what's going on here so I'd appreciate any help. Here's a copy of my read method, not sure how helpful it'll be. Personally I don't see anything wrong (of course not, otherwise I wouldn't be asking for help ).
So, my output file would look like this, whether I enter from keyboard or from a file.
WORK??my name is
streetname thiscity mystate 11111
As for my read from keyboard method, here's a tiny bit (I just copied the first few lines as it's a pretty ugly method):
int endOfFile = 0;
cout << "Please enter first name or type -1 to quit: ";
cin >> s;
if (s == "-1")
endOfFile = -1;
cout << "Please enter middle name: ";
cin >> s;
cout << "Please enter last name: ";
cin >> s;
etc. & etc.
Basically my read from file is the same, just modified.
(My Student constructor is declared but at the moment empty.)
Any suggestions?? I'm probably missing something really obvious, aren't I?
Thanks in advance, smart folks!
As unlikely as it seems, maybe your getter/setter functions have bugs?
Incidentally, both your write() and keyRead() member functions look like they are better off implemented as non-member non-friend functions. In particular, write() looks like it should be an overloaded operator<< for std::ostream instead.
If you have concerns about using non-member functions when writing object oriented code, read:
I finally found the problem was actually in my for loop as I read things in. I had it reading a blank entry. >_< Oh well, it's fixed.
Thanks so much for the links, I really appreciate it. I've read through one of them and I'll read through the other two in a little bit. I still have a lot to learn about design and making good design choices! :]