C++ &引用;进程终止,状态为-1073741819“;带向量的简单程序

C++ &引用;进程终止,状态为-1073741819“;带向量的简单程序,c++,vector,compiler-errors,codeblocks,C++,Vector,Compiler Errors,Codeblocks,出于某种原因,每当我运行我的程序时,我都会出现“进程终止状态为-1073741819”错误,我读到有人会因为代码块/编译器出错而出现此错误,我只是想在重新安装编译器等之前知道我的代码是否有任何错误。我正在使用code::blocks和GNU GCC编译器 我的代码创建了一个向量,它在一周内存储40个工作小时,并在该向量中创建了一个向量,它存储了表示这5个小时内可用人员的字母 时间表。cpp: #include <iostream> #include "Schedule.h" #inc

出于某种原因,每当我运行我的程序时,我都会出现“进程终止状态为-1073741819”错误,我读到有人会因为代码块/编译器出错而出现此错误,我只是想在重新安装编译器等之前知道我的代码是否有任何错误。我正在使用code::blocks和GNU GCC编译器

我的代码创建了一个向量,它在一周内存储40个工作小时,并在该向量中创建了一个向量,它存储了表示这5个小时内可用人员的字母

时间表。cpp:

#include <iostream>
#include "Schedule.h"
#include <vector>
#include <string>

using namespace std;

/// Creates a Vector which holds 40 items (each hour in the week)
/// each item has 5 values ( J A P M K or X, will intialize as J A P M K)

vector< vector<string> > week(40, vector<string> (5));

Schedule::Schedule(){
        for (int i = 0; i<40; i++){
            week[i][0] = 'J';
            week[i][1] = 'A';
            week[i][2] = 'P';
            week[i][3] = 'M';
            week[i][4] = 'K';
        }
        // test 
        cout << week[1][3] << endl;
    }
#ifndef SCHEDULE_H
#define SCHEDULE_H
#include <vector>
#include <string>

using namespace std;

class Schedule
{
    public:
        Schedule();
    protected:
    private:
        vector< vector<string> > week;

};

#endif // SCHEDULE_H
#include <iostream>
#include "Schedule.h"
#include <vector>
#include <string>

using namespace std;

int main()
{
    Schedule theWeek;
}
#包括
#包括“附表h”
#包括
#包括
使用名称空间std;
///创建一个包含40个项目的向量(每周每小时)
///每个项目有5个值(J A P M K或X,将初始化为J A P M K)
向量<向量>周(40,向量(5));
日程安排::日程安排(){

对于(inti=0;i这不是复印机的错误

您的构造函数中出现内存错误

您的代码有几处错误,例如,在cpp中,您声明了一个全局向量week,它随后隐藏在构造函数中,因为构造函数将访问Schedule::week

您的cpp应该类似于:

// comment out the global declaration of a vector week ...
// you want a vector for each object instantiation, not a shared vector between all Schedule objects
// vector< vector<string> > week(40, vector<string> (5)); 


Schedule::Schedule()
{
    for (int i=0;i<40;i++)
    {
        vector<string> stringValues;
        stringValues.push_back("J");
        stringValues.push_back("A");
        stringValues.push_back("P");
        stringValues.push_back("M");
        stringValues.push_back("K");
        week.push_back(stringValues);
    }
}

在调用该行代码时,Schedule::week向量中有0个元素(因此week[i]已经是一个错误)。

这不是复印机错误

您的构造函数中出现内存错误

您的代码有几处错误,例如,在cpp中,您声明了一个全局向量week,它随后隐藏在构造函数中,因为构造函数将访问Schedule::week

您的cpp应该类似于:

// comment out the global declaration of a vector week ...
// you want a vector for each object instantiation, not a shared vector between all Schedule objects
// vector< vector<string> > week(40, vector<string> (5)); 


Schedule::Schedule()
{
    for (int i=0;i<40;i++)
    {
        vector<string> stringValues;
        stringValues.push_back("J");
        stringValues.push_back("A");
        stringValues.push_back("P");
        stringValues.push_back("M");
        stringValues.push_back("K");
        week.push_back(stringValues);
    }
}

在调用该行代码时,Schedule::week向量中有0个元素(因此week[i]已经是一个错误)。

这不是复印机错误

您的构造函数中出现内存错误

您的代码有几处错误,例如,在cpp中,您声明了一个全局向量week,它随后隐藏在构造函数中,因为构造函数将访问Schedule::week

您的cpp应该类似于:

// comment out the global declaration of a vector week ...
// you want a vector for each object instantiation, not a shared vector between all Schedule objects
// vector< vector<string> > week(40, vector<string> (5)); 


Schedule::Schedule()
{
    for (int i=0;i<40;i++)
    {
        vector<string> stringValues;
        stringValues.push_back("J");
        stringValues.push_back("A");
        stringValues.push_back("P");
        stringValues.push_back("M");
        stringValues.push_back("K");
        week.push_back(stringValues);
    }
}

在调用该行代码时,Schedule::week向量中有0个元素(因此week[i]已经是一个错误)。

这不是复印机错误

您的构造函数中出现内存错误

您的代码有几处错误,例如,在cpp中,您声明了一个全局向量week,它随后隐藏在构造函数中,因为构造函数将访问Schedule::week

您的cpp应该类似于:

// comment out the global declaration of a vector week ...
// you want a vector for each object instantiation, not a shared vector between all Schedule objects
// vector< vector<string> > week(40, vector<string> (5)); 


Schedule::Schedule()
{
    for (int i=0;i<40;i++)
    {
        vector<string> stringValues;
        stringValues.push_back("J");
        stringValues.push_back("A");
        stringValues.push_back("P");
        stringValues.push_back("M");
        stringValues.push_back("K");
        week.push_back(stringValues);
    }
}

在调用该行代码时,Schedule::week向量中有0个元素(因此week[i]已经是一个错误)。

使用GDB并运行它,然后使用backtrace。
vectorweek(40,vector(5));
-这将创建一个名为week的全局矩阵变量(不要与
Schedule::week
混淆)。这是故意的吗?我假设您想在构造函数中初始化成员变量;如果是这样,您应该在构造函数中写入
this->week
,或者删除/重命名全局变量声明,或者将全局声明放在命名空间中。使用GDB并运行它,然后使用回溯。
vectorweek(40,vector(5) );
-这将创建一个名为week的全局矩阵变量(不要与
Schedule::week
混淆)。这是故意的吗?我假设您想在构造函数中初始化成员变量;如果是这样,您应该在构造函数中写入
this->week
,或者删除/重命名全局变量声明,或者将全局声明放在命名空间中。使用GDB并运行它,然后使用回溯。
vectorweek(40,vector(5) );
-这将创建一个名为week的全局矩阵变量(不要与
Schedule::week
混淆)。这是故意的吗?我假设您想在构造函数中初始化成员变量;如果是这样,您应该在构造函数中写入
this->week
,或者删除/重命名全局变量声明,或者将全局声明放在命名空间中。使用GDB并运行它,然后使用回溯。
vectorweek(40,vector(5) );
-这将创建一个名为week的全局矩阵变量(不要与
Schedule::week
混淆)。这是故意的吗?我假设您想在构造函数中初始化成员变量;如果是这样,您应该在构造函数中写入
this->week
,或者删除/重命名全局变量声明,或者将全局声明放在命名空间中。