I'm making a program, and I'm at the beginning where I'm just reading the information in. The goal of this short bit of code is to read in a date (when I finish the program it should be able to read in multiple dates from a file, but I'm keeping it simple for now).
The only thing the input file has in it is a date in dd/mm/yyyy form for now. Here's the code:
-----------------------
#include <iostream>
#include <cstdlib>
#include <fstream>
#include <string>
#include <cstring>
int main()
{
int month=0, month2=0, day=0, day2=0, year=0, year2=0;
ifstream infile;
infile.open("input.txt");//change fileName to w/e name you end up using
if (infile.fail("input.txt")){ cout<<"Did not open";
exit(1);
}
infile>>month;
infile.ignore(1000,'/');
infile>>day;
infile.ignore(1000,'/');
infile>>year;
infile.ignore(1000,'/');
cout<<month<<" "<<day<<" "<<year;//debugging
system("PAUSE");
return 0;
}
When I compile this it gives me an error at the "if" statement where I'm checking to see if the file opened. If I take out that whole if statement, my output is 0 0 0, leading me to believe that the file isn't opening for some reason. Is it something wrong with the code?