我搭建了一个win32控制台应用程序,源码如下:
#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;
}
当我调试代码时,我发现控制台没有返回任何消息,也就是说,main函数仍然被调用?而且我不知道我的析构函数是否按我希望的那样工作..
我是一名 C++ 大一新生,这是我第一次在这里发帖……(对不起我的英语不好……我希望我能得到一些帮助……TT)