May 4th, 2013, 10:51 PM
Need a little help on C++ file reading
I was given these instructions for my college programming assignment, and I have done parts 1 and 2, and am having trouble on part three.
1. Use a function named PromptUser() to ask the user for a filename. It will return the
filename as a string object.
2. Open the filename for reading. If you cannot open the filename given, prompt the
user for another. Repeat this until you can open the user's file.
3. Use a function named ReadData() that will take a reference to an integer vector as
the first parameter and a reference to a file stream as the second parameter. It will
make sure the stream is open, then read all the data from the stream and place that
data into the vector. If the file is not open at the beginning of the function, the
function will return a 1, otherwise it will return 0. The main program should check
the return value of this function. If there is an error, give the user an error message
and then end the program.
Our professor gave us the functions, just without the definitions. So far this is what I have
I have no idea where to begin on the second method. Any help is appreciated, thanks a ton.
bool working = true;
while(working == true)
cout << "Please enter a file name: " << endl;
cin >> filename;
cerr << "Could not open: " << filename << endl;
working = false;
int ReadData(vector<int>& theData, ifstream& in)
Click Here to Expand Forum to Full Width