Hi guys, I need some help with file input output. I have a file that has a array size on the first line followed by a 2d array. The array size can change. I need to read this file, and place the array in a array variable. But im not quite sure how to handle this So far I am only able to pull the array size.
EX:
file.txt
4 4
1 2 3 4
5 6 7 8
9 10 11 12
13 14 15 16
#include <iostream>
#include <fstream>
using namespace std;
int row;
int col;
void getSize(){
ifstream infile ("maze1.txt", ios::in);
if (infile.fail())
{
ofstream outfile ("maze1.txt", ios::out);
if (outfile.fail())
{
cout << "Problems opening up maze1.txt" << endl;
exit (1);
}
outfile.close();
}
infile >> col >> row;
infile.close();
}
main()
{
getSize();
cout << col << " " << row << endl;
}
Any help will be appreciated.