Question: C++ help So I am not extracting my code right from my .dat file, it's opening but when I output it my vector is 10,000

C++ help

So I am not extracting my code right from my .dat file, it's opening but when I output it my vector is 10,000 elements from 0 to 9,999. Why is it doing this rather than reading from my file? Here is my code:

#include #include #include #include

using namespace std;

int main() {

int rows = 25; int cols = 0; string filename; int min; int max;

while (rows != cols || cols == 2 * rows) { cout << "enter the number of rows" << endl; cin >> rows; cout << "enter the number of columns" << endl; cin >> cols; } vector> data(rows, vector(cols)); //cout << "enter filename" << endl; //cin >> filename; filename = "map-input-100-100.dat";

ifstream myReadFile; myReadFile.open("map-input-100-100.dat");

while (!myReadFile.eof()) {

for (int i = 0; i < rows; i++) { for (int j = 0; j < cols; j++) { myReadFile >> data[i][j]; } }

for (int i = 0; i < rows; i++) { for (int j = 0; j < cols; j++) { cout << data[i][j] << " "; } }

system("pause"); return 0;

} }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!