C++;在Eclipse中,正在工作的程序部分现在冻结 我在Eclipse 2019-09中用C++编写了一个遗传算法来寻找最佳的飞机着陆计划。我一直在分段编写程序,从一开始就将它们添加到代码中,然后对它们进行测试。声明一些变量和常量后,我的程序打开一个包含我的数据的文件,将其读入对象类型的数组,然后打开第二个文件以分离数据,然后进行一些初始解决方案。所有这些都奏效了

C++;在Eclipse中,正在工作的程序部分现在冻结 我在Eclipse 2019-09中用C++编写了一个遗传算法来寻找最佳的飞机着陆计划。我一直在分段编写程序,从一开始就将它们添加到代码中,然后对它们进行测试。声明一些变量和常量后,我的程序打开一个包含我的数据的文件,将其读入对象类型的数组,然后打开第二个文件以分离数据,然后进行一些初始解决方案。所有这些都奏效了,c++,eclipse-cdt,C++,Eclipse Cdt,然后,我添加了代码来填充最初生成的mu。现在,我的程序在打开第一个数据文件(成功)后停止。它甚至不会读取数据。我没有改变代码的那一部分;我所有的更改都将在程序中稍后进行。我把我的主程序放在它停的地方。打印“从文件读取”后,它停止运行 我还将包括在此点之前调用的唯一类 很抱歉,我的所有代码都不能正确地进入代码块 有人知道是什么导致了这一切吗 #include <iostream> #include <fstream> #include <string> #inc

然后,我添加了代码来填充最初生成的mu。现在,我的程序在打开第一个数据文件(成功)后停止。它甚至不会读取数据。我没有改变代码的那一部分;我所有的更改都将在程序中稍后进行。我把我的主程序放在它停的地方。打印“从文件读取”后,它停止运行

我还将包括在此点之前调用的唯一类

很抱歉,我的所有代码都不能正确地进入代码块

有人知道是什么导致了这一切吗

#include <iostream>
#include <fstream>
#include <string>
#include <bits/stdc++.h>
#include "Airplane.h"
#include "LandingTime.h"
#include "LL.h"

//#include "Parameters.h"

using namespace std;


// Global Parameters and Constants -- change values here to fit your problem
const int P = 20; // number of planes
const int generationSize = 12;
const int maximumNumberOfGenerations = 5;
const int g = 2; // rate of cost per unit time for early landings
const int h = 3; // rate of cost per unit time for late landings
int seed = 2019;

const string filename = "CodeTestingData20planes.txt";




// Function Declarations
// void myFunction(int param[10])
int FindTotalCost(LandingTime schedule[P]);

int FindCost (int x, int t);

bool IsNotFeasible(LandingTime Solution[P], int sep[4][4]);
// The IsNotFeasible function also fixes some feasibility issues related to separation times


void Sort(LandingTime Solution[P]);

int main()
{
//Collect Data



// Collect array of airplanes
    Airplane airplane[P];
    int ac;
    int ty;
    int a;
    int e;
    int t;
    int l;
ifstream datafile;
datafile.open(filename);
if(!datafile.is_open()){
    cout << "file didn't open";
} else
{
    cout << "Reading from the file" << endl;
    for(int p = 0; p < P; p++)
            {
                  cout << p;
                  datafile >> ac;
                  datafile >> a;
                  datafile >> ty;
                  datafile >> e;
                  datafile >> t;
                  datafile >> l;

                  airplane[p] = Airplane(ac, a, ty, e, t, l);


                   // write the data at the screen.
                   cout << airplane[p].getAircraft() << "\t" << airplane[p].getType() << "\t";
                   cout << airplane[p].getA() << "\t" <<airplane[p].getE() << "\t";
                   cout << airplane[p].getT() << "\t" << airplane[p].getL();
                   cout << "\n";
    }//end of for p loop

    datafile.close();
    cout << "data file closed";

} // end of else
这是class.h文件

#ifndef AIRPLANE_H_
#define AIRPLANE_H_

namespace std {

class Airplane {
public:

    // Class member variables
    int aircraft;   // Airplane identifier
    int A;          // Arrival time in ATC airspace
    int type;       // Type of airplane
    int E;          // Earliest possible landing time
    int T;          // Target landing time based on cruise speed
    int L;          // Latest possible landing time


    Airplane();
    Airplane(int ac, int a, int ty, int e, int t, int l);
    virtual ~Airplane();

    void setAircraft(int ac);
    void setA(int a);
    void setType(int ty);
    void setE(int e);
    void setT(int t);
    void setL(int l);

    int getAircraft();
    int getA();
    int getType();
    int getE();
    int getT();
    int getL();

};

} /* namespace std */

#endif /* AIRPLANE_H_ */

请注意,这一切都在工作,没有任何更改,现在它不工作了。

请使用调试器,它会准确地告诉您程序在哪一行终止,以及为什么终止。我对Eclipse很不熟悉。我在调试器中找不到行号,但程序打印出短语“从文件读取”,但它不会打印p,这告诉我它要么没有进入for循环,要么在进入后就卡住了。这是一个错误的结论
cout可能不相关,但仍然建议阅读:您应该在每次输入后验证流状态,例如,
if(!(datafile>>ac)){std::cerr
#ifndef AIRPLANE_H_
#define AIRPLANE_H_

namespace std {

class Airplane {
public:

    // Class member variables
    int aircraft;   // Airplane identifier
    int A;          // Arrival time in ATC airspace
    int type;       // Type of airplane
    int E;          // Earliest possible landing time
    int T;          // Target landing time based on cruise speed
    int L;          // Latest possible landing time


    Airplane();
    Airplane(int ac, int a, int ty, int e, int t, int l);
    virtual ~Airplane();

    void setAircraft(int ac);
    void setA(int a);
    void setType(int ty);
    void setE(int e);
    void setT(int t);
    void setL(int l);

    int getAircraft();
    int getA();
    int getType();
    int getE();
    int getT();
    int getL();

};

} /* namespace std */

#endif /* AIRPLANE_H_ */