Reading Date From File

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
Firstly, your declaration syntax is incorrect. Try:
ifstream in;

For your second question, a few methods can be found here:
http://stackoverflow.com/questions/14218894/number-of-days-between-two-dates-c
Topic archived. No new replies allowed.