I'm very new to C++ and I have an assignment that has to do with reading in a text file and finding the average of each line. Then pushing the final scores to a vector. I can read in the file but I don't know how to take each line of integers and find the average.
This is the file I am supposed to read in.
79 72 78 71 73 68 74 75 70
89 96 91 94 95 92 88 95 92
81 93 85 84 79 78 90 88 79
100 86 99 98 97 96 95 94 92
60 82 64 65 63 62 61 67 64
92 100 81 82 83 84 85 86 87
91 74 76 77 78 81 83 80 88
60 65 68 72 74 76 77 78 73
99 91 93 94 96 95 97 98 74
81 89 75 77 79 81 83 85 78
How do I take each line of integers from the file and find the average? This is my code so far.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
|
void getFileContent(string myLine2){
string inFileName = "lab1.txt";
ifstream inFile;
inFile.open(inFileName);
while (!inFile.is_open()) {
cout << "Unable to open default file/file path.\nPlease enter a new file/file path:" << endl;
cin >> inFileName;
inFile.open(inFileName);
}
cout << "FILE IS OPEN!!!\n";
while(inFile >> myLine2){
getline(inFile, myLine2);
cout << myLine2 << endl;
}
}
|