A text file data.txt, contains at most 80 student marks in an exam. Each mark is out of 100. The last number in the file is -1 indicating that there is no more data in the file.
read all the marks in the data file and store in an array, print all the elements in the array
1
Expert's answer
2018-04-10T02:25:11-0400
#include <iostream> #include<array> #include<fstream> #include<ctime> int main() { std::array<int,80> _marks;
std::ifstream _read("data.txt"); int i = 0; int _getnumber = 0; while (_read>>_getnumber) {
if (_getnumber==-1) break; _marks[i] = _getnumber; i++; } for (auto i:_marks) std::cout<<i<<' '; return 0; }
Comments
Leave a comment