I would like to write a c++ code that read a text file test.txt and write the conetent into several arrays. the file looks like:
[7,13,17]
[[0,1,1,0,0,1,0,0,1,0,0,0,0,0,1,0,0],
[1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0],
[1,0,0,1,0,0,0,0,0,1,1,1,0,0,1,0,0],
[0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0],
[0,0,0,0,0,1,0,0,1,0,0,0,1,1,0,0,0],
[0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0]]
the code i have written like
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
int parameter[10];
int physical[7][7];
const char* filename;
filename = "src/cplex_N7.txt";
ifstream f(filename, ios::in);
if (!f) {
cerr << "No such file: " << filename << endl;
throw(1);
}
f >> parameter >> physical ;
// cout content
return 0;
}
but i always got errors and wrong output, could you please help with doing this in the best way. I mean can i read the file without for loop or without handling the commas and splitters.