I have a .dat file containing full of integers 100 by 100, and I am trying to transfer x rows and x columns into a new vector, I've managed to ge the first row with the desired columns but stuck in trying to get to the next line and until to the x rows, please give help.
also some help on the display part, I'm not sure how to display a vector with more than one rows and columns. Tried data.at(i).at(j)
double for loop but unsuccessful
//variable
int row, col;
string fname;
ifstream file;
vector<vector<int>> data;
//input
cout << "Enter the number of rows in the map: "; cin >> row;
cout << "Enter the number of columns in the map: "; cin >> col;
cout << "Enter the file name to write: "; cin >> fname;
//open file
file.open(fname, ios::in); // map-input-100-100.dat map-input-480-480.dat
//copy specified data into vector
int count = 0, temp = 0;
string line;
while (count < row)
{
for (int i = 0; i < col; ++i)
{
file >> temp;
data[count].push_back(temp);
}
++count;
getline(file, line);
stringstream ss(line);
}
//output
for (int i = 0; i < data.size(); i++)
{
for (int j = 0; j < data[i].size(); j++) cout << data[i][j] << ' ';
cout << endl;
}
This is my code so far