reading file with array

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
> 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.