Reading Date From File
Mar 21, 2014 at 1:54am UTC
Hi guys need a help here.
So here's my file content:
J001 Graham Bell 145 20/03/2012 23/03/2012
my current code is.
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 28 29 30 31 32 33
#include<iostream>
#include<fstream>
#include<string>
using namespace std;
int main()
{
fstream in;
char cust_id;
int room_no;
string cust_name, check_in, check_out;
in.open("hotel.txt" );
if (!in)
{
cout << "File could not be located.\n" ;
}
while (!in.eof())
{
in >> cust_id >> cust_name >> room_no >> check_in >> check_out;
}
in.close();
cout << "Customer ID:" << cust_id << endl;
cout << "Customer Name:" << cust_name << endl;
cout << "Room No:" << room_no << endl;
cout << "Date checking in:" << check_in << endl;
cout << "Date checking out:" << check_out << endl;
system("pause" );
return 0;
}
I have 2 problems right here.
1)I have no idea why it could not load or read my file.When i run the codes.I was prompted with a blank cmd instead of "File could not be located.
2)How do I calculate how many days that a customer been staying inside the hotel?
For example:20/03/2012-23/03/2012
TQ
Mar 21, 2014 at 4:59pm UTC
Topic archived. No new replies allowed.