| tacoman359 (4) | |||||
|
Hi everyone, I can't seem to figure this out. I'm trying to get data from a file (lines 46-48) and then use that data in some functions. This is working out fine except when I try to loop it to get a new set of data. My program seems to continue to use the old data, even though the loop is in place. Any suggestions? Thanks!
And this is the data file:
| |||||
|
|
|||||
| Cubbi (1584) | |
After you read the first guy's retirement with indata >> retirement; the end of line is not yet processed.The next thing you do with that file (beside the erroneous "while not eof") is getline(indata, name). That getline sees the endline and stores an empty string in "indata".The next thing you do with that file is indata >> payRate;, which sees the letter 'M', cannot store that in the variable payRate, and sets the error flag on your stream.No further input takes place, which you see as "continue to use the old data," At the very least, consume that endline after indata >> retirement (e.g. by calling indata.ignore();) | |
|
|
|
| tacoman359 (4) | |
|
Thanks a lot, I appreciate the help! There's also one other thing - I'm not very familiar with setw(), but I'm trying to align all the names, gross pay, deductions, and net pay amounts on the right (so they end at the end of the = signs). Google isn't seeming to help me and I feel like I've tried everything. Any ideas? | |
|
|
|
| HellfireXP (46) | |
| Did you try just a simple tab? "\t"; | |
|
|
|
| tacoman359 (4) | |
| Well that wouldn't right align it (guess I should have made that a little more clear). I need the amounts and names right aligned. | |
|
|
|
| Cubbi (1584) | |
|
right alignment manipulator is called std::right : http://www.cplusplus.com/reference/ios/right/ http://en.cppreference.com/w/cpp/io/manip/left | |
|
|
|
| tacoman359 (4) | |
I've read those and I don't understand what I'm doing wrong. Isn't my code right? shouldn't cout << "Name:" << right << setw(26) << name << endl; right align the name string?
| |
|
|
|
| Cubbi (1584) | |
|
it certainly should: http://ideone.com/wdLcIZ | |
|
|
|