How do I create an infile with a Mac (Xcode)?

I did this but there was an error. I don't know how you can do this.

// open the infile
ifstream inFile;
inFile.open ("in6s17.txt");


//display error message
if (!inFile) {
cout << "Error opening infile." << endl;

}

//write to infile
else
{
for (int count=0; count<MONTHS; count++)
rainfallAmount[count];

}

//close the infile
inFile.close();


It keeps saying that there's an error opening infile.


Maybe the file is not there. Anyway it's better to use perror to get a clearer error message.
1
2
3
4
5
#include <stdio.h>
//display error message
if (!inFile) {
  perror("FILE ERROR: ");
}


http://www.cplusplus.com/reference/cstdio/perror/
Topic archived. No new replies allowed.