Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

The program keeps terminating so I do not know why the file will not open. Here

ID: 3572000 • Letter: T

Question

The program keeps terminating so I do not know why the file will not open. Here is that part of that code. Please let me know what I can do to maybe fix this problem. Thank you.


ifstream myFile;
myFile.open("Project4text.txt");


if (!myFile.is_open()) {
  exit(EXIT_FAILURE);
}

else {
  for (int k = 0; k < in; k++) {
   myFile >> m[k][0] >> m[k][1] >> m[k][2];
  }

  for (int x = 0; x < in; x++) {
   for (int y = 0; y < 3; y++) {
    cout << m[x][y] << " ";
   }
  }
}

Explanation / Answer

iostream stream in c++ is classified into two different classes

istream: read from files.

ostream :write to file.

if you wanted to open a file to read data from a file you need to open it using istream else opening of file to write data is done through ostream.

Your to clear in the question to open a file for writing of data or read the data from a file yet but your code seems to write the data from a file so, you can change the istream to ostream and try it.