Hey guys, I'm a university student and programming in c++ is an elective I'm taking. I've been having a hard time with this course but I'm stillt trying at it. Im in my first year, first semester and I'm new to this site.
I'm having difficulties reading data from my txt file (views.txt). The views txt file contains the number of times a youtube video has been viewed in any given day and my program is suppose to read the data from this file. The amount of days is unknown before hand but a negative value means that there is no more data in the file. I have attached both my cpp file and the view.txt file. Please help.
The second part of the assignment reads as follows
# include <iostream>
# include <fstream>
#include <string>
using namespace std;
int main()
{
int view[25]= {0};
int i;
int amtofdays[366]; // assume file contains view values for at most 366 days
ifstream myfile;
myfile.open("views.txt");
if(!myfile.is_open())
{
cout << "The file was not successfully opened"<<endl;
cout << "Check that the file currently exists"<<endl;
return 0;
}
while(!myfile.eof())
{
for (int i=0; i < 25 ; i++)
{
myfile>>view[i];
/* if(i>999){
ofstream outputfile;
outputfile.open("stats.txt");
outputfile << i;
outputfile.close();
*/
}
}
myfile.close();
//DISPLAYS THE CONTENTS OF THE VIEW TXT DOC
for (int i=0; i < 25 ; i++)
{
cout<< view[i] ;//<< ' ';
cout<< " \n";
}
system("pause");
return 0;
}