C++ 为什么我的主要功能不能';你终于回不来了?
我构建了一个win32控制台应用程序,下面是源代码:C++ 为什么我的主要功能不能';你终于回不来了?,c++,file-io,destructor,C++,File Io,Destructor,我构建了一个win32控制台应用程序,下面是源代码: #include <iostream> #include <fstream> #include <vector> #include <string> using namespace std; struct CPassenger { string name; string ID; string seat; }; struct CFlight { string
#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;
}
#包括
#包括
#包括
#包括
使用名称空间std;
结构CPassenger
{
字符串名;
字符串ID;
绳座;
};
结构CFlight
{
字符串flNum;
字符串目的地;
整数金额;
国际订票;
字符串离开时间;
串下降时间;
向量表;
};
类照明系统
{
公众:
CFlightSystem();
~CFlightSystem();
私人:
矢量飞行;
};
CFlightSystem::CFlightSystem()
{
ifstream INFLE(“flight.txt”);
如果(!infle)
{
赛尔普兰目的地
>>飞机.数量>>飞机.预订
>>飞机起飞时间>>飞机降落时间;
对于(int i=0;i!=飞机预订;++i)
{
注册会计师tmp;
填充>>tmp.name>>tmp.ID>>tmp.seat;
平面列表推回(tmp);
}
飞行。推回(飞机);
}
infle.close();
}
CFlightSystem::~CFlightSystem()
{
流出流文件(“flight.txt”);
如果(!outfile)
{
cerrMy的建议是,要么在调试器中单步执行程序,要么在不同点插入print语句,以确定它在停止响应之前能走多远。此外,“fall time”对我来说并不是一个特别好的变量名选择(除非这是针对NTSB系统;-))在正常情况下不打印任何内容时,您希望控制台如何显示任何内容?您可能希望添加cerr您的意思是程序挂起还是不打印到控制台但程序被执行了?而(!infle.eof())
是错误的:。