i want first two integers in free variables like height is 3 and width is 7,and for other i want to put them into a double array.As long as I tried to do as i read so many questions and comments about problems like this, I could not make it work..I need some suggestions maybe some codes to work it out since as i mentioned above I am so noob about c++. Thank you for your time
#include <iostream>
#include <stack>
#include <stdlib.h>
#include <vector>
#include <fstream>
usingnamespace std;
int main(){
ifstream in;
in.open("input");
vector<vector<int> > floor;
int height;
in >> height;
int width;
in >> width;
for(int i=0;i<height;i++){
for(int j=0;j<width;j++)
{
in >> floor[j][i];
cout << floor[j][i] // in order to check whether it is working or not
}
}
return 0;
}
You need to expand a vector before you can put something in it. You could set it's size in the constructor (except that on line 14 you don't know what it is yet). You should use the resize method floor.resize(width); before the for loop. You could also resize all vectors floor[i] in the first for loop, or you could read integers from "in" to a temporary variable and then push_back it into floor[i].