-1
由于某种原因我得到“进程终止状态-1073741819”错误,每当我运行我的程序,我读过一些人因为错误而得到这个错误用代码块/编译器,我只想知道在我重新安装编译器之前是否有任何代码有问题。我使用的是code :: blocks和GNU GCC编译器。“进程终止状态-1073741819”简单程序与向量
我的代码创建了一个存储一个星期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并运行它,然后使用回溯。 – Cinch 2015-04-02 08:39:22
'vector> week(40,vector (5));' - 这会创建一个名为week的全局矩阵变量(不要与Schedule :: week混淆)。这是故意的吗?我假设你想在构造函数中初始化成员变量;如果是这样,你应该在构造函数中写'this-> week',或者删除/重命名全局变量声明,或者将全局声明放在名称空间中。 –
utnapistim
2015-04-02 08:49:17