reading file with array
Nov 24, 2019 at 3:56am Nov 24, 2019 at 3:56am UTC
ask the user for a course name and see if it is in the array. If found, the program should print “Found at” followed by the index where the value was found.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main ()
{
string courses[6];
ofstream myfile;
int total;
myfile.open ("MyCourses2019.txt" );
myfile<<"Classes student is taking this semester.\n" ;
cout<<"How many courses are you taking this semester? " ;
cin>>total;
cin.ignore(1000,'\n' );
for (int i=0; i<total; i++)
{
if (i<6)
{
getline (cin,courses[i]);
myfile<<courses[i]<<endl;
}
}
myfile.close ();
}
after I did
1 2 3 4 5 6 7 8 9 10 11 12 13 14
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main ()
{
const string courses[6];
string word;
ifstream fin;
fin.open("MyCourses2019.txt" );
if (!fin)
cout<<"Error opening data file\n" ;]
but I do not know what to do after.
Last edited on Nov 24, 2019 at 4:33am Nov 24, 2019 at 4:33am UTC
Nov 24, 2019 at 7:16am Nov 24, 2019 at 7:16am UTC
> myfile<<courses[i]<<endl;
Well you did this to write it.
So perhaps this to read it.
fin >> courses[i]
Topic archived. No new replies allowed.