【发布时间】:2015-04-02 08:35:00
【问题描述】:
由于某种原因,每当我运行我的程序时,我都会收到“进程以状态 -1073741819 终止”错误,我读到有些人因为代码块/编译器出现问题而收到此错误,我只是想在我重新安装编译器等之前知道我的代码是否有任何问题。我正在使用 code::blocks 和 GNU GCC 编译器。
我的代码创建了一个向量,该向量存储一周内 40 个工作时间,并在该向量内创建一个向量,该向量存储代表这些小时内可用的 5 人的字母。
Schedule.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
main.cpp:
#include <iostream>
#include "Schedule.h"
#include <vector>
#include <string>
using namespace std;
int main()
{
Schedule theWeek;
}
【问题讨论】:
-
使用 GDB 并运行它,然后使用回溯。
-
vector< vector<string> > week(40, vector<string> (5));- 这将创建一个名为 week 的全局矩阵变量(不要与Schedule::week混淆)。这是故意的吗?我假设您要在构造函数中初始化成员变量;如果是这样,您应该在构造函数中写入this->week,或者删除/重命名全局变量声明,或者将全局声明放在命名空间中。
标签: c++ vector compiler-errors codeblocks