Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database And Expert Systems Applications 22nd International Conference Dexa 2011 Toulouse France August/September 2011 Proceedings Part 1 Lncs 6860

Authors: Abdelkader Hameurlain ,Stephen W. Liddle ,Klaus-Dieter Schewe ,Xiaofang Zhou

2011th Edition

3642230873, 978-3642230875

More Books

Students also viewed these Databases questions

Question

Prepare a short profile of victor marie hugo ?

Answered: 1 week ago

Question

Prepare a short profile of Henry words worth Longfellow?

Answered: 1 week ago

Question

What is RAM as far as telecommunication is concerned?

Answered: 1 week ago

Question

Question 1: What is reproductive system? Question 2: What is Semen?

Answered: 1 week ago