Sorting from a file that was read in as a vector

I am trying to read in a file from class Flight which I already made. I believe I've read in the file correctly, but when I go to sort it by departure time, it does output how I want it to. Namely, in a 24 hour format, but it seems to chop off the colon and remaining minutes.

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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/*flight.cpp*/
#include "std_lib_facilities_4.h"
#include "sort.h"

bool compare_dep(const Flight& lhs, const Flight& rhs){
	return lhs.departure < rhs.departure;
	}

ostream& operator<<(ostream& os, const Flight& f){
	os << f.flightno << endl;
	os << f.destination << endl;
	os << f.departure << endl;
	os << f.gateno << endl;
	return os;
}

void read_flights(vector<Flight>& data){
	ifstream file("flight.txt");
	string line;
	Flight f;
	if (file.is_open())
  {
    getline(file,line);
	int i = 1;
    while(!file.eof()){
		bool c = false;
		switch(i){
			case 1:
				getline(file, line, '\t');
				cout << line << endl;
				f.flightno = line;
				break;
			case 2:
				file.ignore(2);
				getline(file, line, '\t');
				cout << line << endl;
				f.destination = line;
				break;
			case 3:
				char a;
				while(c == false){
					file.get(a);
					if(a != '\t') c = true;
				}
				getline(file, line, '\t');
				line = a + line;
				cout << line << endl;
				f.departure = stoi(line);
				break;
			case 4:
				char b;
				while(c == false){
					file.get(b);
					if(b != '\t') c = true;
				}
				getline(file, line);
				line = b + line;
				cout << line << endl;
				f.gateno = line;
				data.push_back(f);
				i = 0;
				break;
			default:
				break;
			}
			++i;
		}
	}
}


int main(){
	vector<Flight> data;
	read_flights(data);
	
	sort(data.begin(), data.end(), compare_dep);
	for(int i = 0; i < data.size(); ++i)
	{cout << data[i] << endl;}
}


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
/*flight.h*/
#include "std_lib_facilities_4.h"

class Flight{
	public:
		string flightno;
		string destination;
		int departure;
		string gateno;
			
		Flight():
			flightno(),
			destination(),
			departure(),
			gateno(){}
};


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
/*sort.h*/
#include "std_lib_facilities_4.h"
#include "flight.h"
using namespace std;

class Sort {
protected:
   unsigned long num_cmps; // number of comparisons performed in sort function
public:
   virtual void sort(vector<Flight>& data) = 0;    // main entry point
   bool testIfSorted(const vector<Flight>& data);        // returns false if not sorted
                                                // true otherwise
   unsigned long getNumCmps() { return num_cmps; }        // returns # of comparisons
   void resetNumCmps() { num_cmps = 0; }
};

class SelectionSort:public Sort {	// SelectionSort class
public:
  void sort(vector<Flight>& data);		// main entry point
};

class BubbleSort:public Sort {		// BubbleSort class
public:
  void sort(vector<Flight>& data);		// main entry point
};
I realize, I could read in an int, that a char for the colon, then another int but I'm not sure how to do this without making a mess out of my code. Any suggestions would be appreciated.
Topic archived. No new replies allowed.