问题描述
我编写了一个 C++ 代码,我在其中读取了一个 CSV 文件并将其存储到一个 2D 数组中,然后将其传递给 Octave 函数 imregionalmax。但是代码给出了分段错误(核心转储)。请帮助我解决这个问题。如果可能,请提供 C++ 代码。我在下面附上我的代码
#include <iostream>
#include <fstream>
#include <sstream>
#include <vector>
#include <octave/oct.h>
#include <octave/octave.h>
#include <octave/parse.h>
#include <octave/interpreter.h>
#define ROW 100
#define COL 1000
int main (int argc,char **argv) {
std::ifstream f;
f.open ("Mat30.csv");
if (! f.is_open()) { /* validate file open for reading */
std::cerr << "error: file open Failed '" << argv[1] << "'.\n";
return 1;
}
std::string line,val;
std::vector<std::vector<float>> array;
while (std::getline (f,line)) { /* read each line */
std::vector<float> v; /* row vector v */
std::stringstream s (line); /* stringstream line */
while (getline (s,val,',')) /* get each value (',' delimited) */
v.push_back (std::stof (val)); /* add to row vector */
array.push_back (v); /* add row vector to array */
string_vector argv_octave (2);
argv_octave(0) = "embedded";
argv_octave(1) = "-q";
octave_main (1,argv_octave.c_str_vec (),2);
octave_value_list in1,in2;
for(octave_idx_type i = 0 ; i < ROW ; i++) {
for(octave_idx_type j = 0 ; j < COL ; j++)
in1(j) = octave_value(array[i][j]);
in2(i) = in1;
}
// segmentation fault (core dumped) occurs here. Execution is not going further
octave_value_list out = feval ("imregionalmax",in2,1);
return 0;
}
我使用的是 ubuntu 18.04,我的机器上安装了 Octave 我通过编写终端来运行代码“mkoctfile --link-stand-alone file_name.cpp -o file_name && ./file_name”
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)