Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I am unable to get my code to work, at this point I am basically justt trying to

ID: 3906380 • Letter: I

Question

I am unable to get my code to work, at this point I am basically justt trying to get the file "map-input-100-100.dat" to open. Does anyone have a solution?

#include

#include

#include

#include

#include

#include

using namespace std;

int main() {

int num_cols = 0;

int num_rows = 0;

vector sizeCheck;

vector > dataInput;

vector> Rvals;

vector> Gvals;

vector> Bvals;

string ele_File = "";

cin >> num_cols >> num_rows;

ifstream inputFile;

inputFile.open("map-input-100-100.dat");

if (!inputFile) {

cout << "Error: Unable to open file";

return 0;

}

for (int i = 0; i

{

for (int j = 0; j < num_cols; j++)

{

inputFile >> dataInput.at(i).at(j);

}

}

inputFile.close();

return 0;

}

Explanation / Answer

#include<iostream>
#include <vector>
#include<fstream>

using namespace std;

int main() {
int num_cols = 0;
int num_rows = 0;
vector<int> sizeCheck;
vector <vector<int> > dataInput;
vector<int> Rvals;
vector<int> Gvals;
vector<int> Bvals;
string ele_File = "";
cin >> num_cols >> num_rows;
ifstream inputFile;
inputFile.open("map-input-100-100.dat");
if (!inputFile) {
cout << "Error: Unable to open file";
return 0;
}
for (int i = 0; i<num_rows; i++)
{
for (int j = 0; j < num_cols; j++)
{
inputFile >> dataInput[i][j];
}
}
inputFile.close();
return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote