我正在为 uni 做一个作业(.csv-parser)。在编译后尝试运行代码时,它会返回 SegFault 11。
这是我的代码:
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <sstream>
int main (int argc, char** argv) {
string line;
string buffer;
vector<vector<string> > database;
vector<string> dataset;
//bool start = true;
ifstream denkmaeler;
denkmaeler.open(argv[1]);
ifstream denkmal;
denkmal.open(argv[1]);
int semic = 1;
//int semic2 = 1;
int zaehler = 0;
if (denkmal.is_open()){
(getline(denkmal, buffer));
for (int i = 0; i < buffer.length(); i++ ){
if(buffer[i] == ';'){
semic++;}
}
}
denkmal.close();
if(denkmaeler.is_open()) {
//if (counter < 1) {
while (getline(denkmaeler, buffer));
if (line.back() == *argv[2]) {
line += argv[2];
stringstream ss(line);
while (getline(ss, line, *argv[2])) {
dataset.push_back(line);
database.push_back(dataset);
dataset.clear();
}
}
}
for (int x=0, y=semic; x < semic; y=database.size(), x++, y++){
if (x > semic){
x=0;
cout << '\n' << "-------------------------------" << '\n' << endl;
}
if (database[y][0].length() == 0){
database[y][0] = "not available";
}
cout << database[x][0] << " : " << database[y][0] << endl;
}
}
如果有人能够指出我的错误,我将非常感激。我读了一些帖子,指出问题可能是一个数组,但我不确定那是怎么回事。
最佳答案
对于段错误,最好使用可以准确显示错误在哪里(哪一行)的调试工具!
我正在使用gdb,我建议你谷歌它
关于c++ - 尝试运行已编译的 C++ 代码时出现段错误 11,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55107409/