I cant seem to get my program to find the .txt file I have created. Is there a particular spot I should create it? The code I have is below.
The program just automatically goes to error.
ifstream inputFile ("PaintInfo.txt");
inputFile.open ("PaintInfo.txt");
if (!inputFile)
{
cout << "Unable to open the file." << endl << endl;
exit (1);
}
string lastname;
double roomnumber, wallcolor, ceilingcolor, windowcount, doorcount;
double height, width, depth;
The first two lines are redundant. I don't know if attempting to open a file without closing the previous would cause your problem, if any.
1 2 3 4 5
ifstream file("file.txt");
//or
ifstream file;
file.open("file.txt");
//but not both
Make sure your file is in either:
1) the same directory as the project file if you are running the program with an IDE
2) the same directory as the executable if you are running the program directly
Also, instead of exit(1), you could have a simple return 1;.