My problem is how to use correctly the function infile.open()
.
I have a class that, among the others, has the following public properties:
class myclass {
public:
int rows
int columns
const char* array_file
}
All values are given at run-time.
When I call the function that uses a member of the class I have (pt is a pointer to a member of the class)
#include <vector>
#include <fstream>
#include <iostream>
typedef std::vector< std::vector<int> > Matrixint;
void function(myclass* pt) {
Matrixint array_name(pt->rows, std::vector<int>(pt->columns));
std::ifstream infile;
infile.open("%s", pt->array_file); // my problem: is this correct?
for (int a = 0; a < pt->rows; a++) {
for (int b = 0; b < pt->columns; b++) {
infile >> array_name[a][b] ;
}
}
infile.close();
}
Is this way of opening/reading the file correct?
The data in the file will be formatted as in this question (please note: only the array will be present in the file, no other data)