C++ HELP!!!! 1. Create an array of ints in main() 2. Pass the array as a parameter to a function to read in the int length data. You must make the prototype look like this void read_data(ifstream& input, int arr[]); 3. In the read function, read mixed-type input data (using getline() and “cin >>” statements) 4. In the read function, put the length data into the array 5. In main, sum up the array of ints. To sum the elements, you will either have to initialize the array with zeros or pass a third parameter to read_data
How far have you gotten, which part are you stuck on?
I'm pretty much stuck on everything. However, the part i'm stuck on right now is opening a .txt file until eof in a prototype which looks like this: void readData(ifstream& input, int arr[])
That is just a function that takes a file pointer and an array. Did you already create your pointer and array?
We have not covered pointers and we cannot use that in our code. I think I may have opened the file right: void readData(ifstream& input, int arr[]) { ifstream schedule; string line; schedule.open ("schedule.txt", ifstream::in); if (schedule.is_open()) { getline(schedule, line); while(!schedule.eof()) { getline(schedule, line); } } schedule.close(); system("PAUSE"); } Is that correct?
You don't have to create a new file pointer because you being passed one "ifstream& input" when the function is called.
what do you mean? are you saying that I should change "ifstream& input" to "ifstream& schedule"
Join our real-time social learning platform and learn together with your friends!