I have a file that has the layout:
0 0
0 1
1 0
1 1
I want to read it into a multidimensional array and use the values. The thing is I don't know how to read it in.. I can read the amount of columns and rows the file has.. but I don't know how to read the values.
Also I want it to make a Multidimensional array depending on the amount of columns and rows and then read them into their respective cells.. If the file only contains numbers.. How do I make it read the values in as Integers?
How do I do it?
My Attempt.. It's not homework but it's nice to know how..
#include <iostream>
#include <fstream>
#include <string>
#include <windows.h>
#include <sstream>
using namespace std;
int main()
{
int col, row;
row = 0;
col = 0;
fstream InFile;
InFile.open("test.txt", ios::in | ios::out);
string line;
while(getline(InFile, line))
{
row++;
stringstream s(line);
string token;
while(getline(s, token, ' '))
{
col++;
table[row][col];
}
}
//table [row][col];
string table [row][col]; //Create A MultiDimensional Array depending on the amount of columns and rows..
cout <<"Rows: "<< row << endl;
cout<<"Columns: "<< col/row <<endl;
cout<<table[1][2];
InFile.close();
}