Wednesday 28 August 2013

why my main function couldn't return at last?

why my main function couldn't return at last?

I build a win32 console application program, here is the source code:
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
using namespace std;
struct CPassenger
{
string name;
string ID;
string seat;
};
struct CFlight
{
string flNum;
string destination;
int amount;
int booking;
string departureTime;
string fallTime;
vector<CPassenger> list;
};
class CFlightSystem
{
public:
CFlightSystem();
~CFlightSystem();
private:
vector<CFlight> flight;
};
CFlightSystem::CFlightSystem()
{
ifstream infile("flight.txt");
if(!infile)
{
cerr<<"No input file!"<<endl;
exit(1);
}
while(!infile.eof())
{
CFlight plane;
infile>>plane.flNum>>plane.destination
>>plane.amount>>plane.booking
>>plane.departureTime>>plane.fallTime;
for(int i=0;i!=plane.booking;++i)
{
CPassenger tmp;
infile>>tmp.name>>tmp.ID>>tmp.seat;
plane.list.push_back(tmp);
}
flight.push_back(plane);
}
infile.close();
}
CFlightSystem::~CFlightSystem()
{
ofstream outfile("flight.txt");
if(!outfile)
{
cerr<<"No output file!"<<endl;
exit(1);
}
for(vector<CFlight>::iterator iter=flight.begin();
iter!=flight.end();++iter)
{
outfile<<iter->flNum<<' '<<iter->destination<<' '
<<iter->amount<<' '<<iter->booking<<' '
<<iter->departureTime<<' '<<iter->fallTime<<' '
<<endl;
for(vector<CPassenger>::iterator it=(iter->list).begin();
it!=(iter->list).end();++it)
{
outfile<<it->name<<' '
<<it->ID<<' '
<<it->seat<<endl;
}
}
outfile.close();
}
int main()
{
CFlightSystem management;
return 0;
}
when I debug the code , I found that the console didn't return any messege
that is to say, the main function is still called ? and I don't know if my
destructor is working as I hope..
I'm a c++ freshman, and it's my first time posting here... (sorry for my
poor English..I hope I can get some help ..T.T)

No comments:

Post a Comment