I am writing a program as an exercise from Accelerated C++. (3-5)
I'm inputting names into a vector of strings, and so far the book has used/suggested
as the way to fill the vector. When the user enters end-of-file (Ctrl-Z for me) the loop is terminated.Code:while (cin >> x) myVector.push_back(x);
In my program, the user inputs additional information to be stored in a different vector. However, it never stops to get the input and crashes as it tries to do calculations with what should have been the additional input. I tested a few things and it seems that the additional variables are filled with crazy numbers. I thought it was somehow skipping the input and leaving in the variables the garbage that was assigned to the variables since I didn't initialize them myself. I tried initializing the variables to a number (they're doubles) but the same numbers keep popping up. Therefore, I assume that it really *is* drawing from the input buffer, just not anything the user has inputted. The only reason for this that I can think of is that the EOF used to terminate the first loop is closing off or messing up or something the input stream that I intend to use later on in the program.
I realize that I could have the user input something like "done" in the first loop to terminate it that way instead of the EOF method, but I'm reading this book to overcome some bad habits, so I only use what the book has taught me so far, even if I know it is standard code and will work OK. Thankfully, I can use if statements, but I can only assume that the authors intended for me to use the EOF method since they haven't really discussed the input steam, buffers, the true nature of EOF, or any other way to fill a vector with an unknown number of variables - which means there should be (shouldn't there?) a way to do it like this.
All of this babbling leads to this: Is the EOF used to terminate an input loop early in the program inhibiting me from inputting data later on? If not, why might it be filling my variables with strange numbers and crashing? I googled, I searched the boards and the FAQ (but maybe for the wrong things....)
BTW, I'm using Dev C++ 4, on XP.