how to take input in 2d vector in c++ code example
Example 1: how to get size of 2d vector in c++
myVector[
Vector[0, 4, 2, 5],
Vector[1, 4, 2]
];
/*When you call for myVector[1].size() it would return 3 and [0] would return 4.
For the amount of rows (int vectors) in the 2d vector, you can just use myVector.size()
You can run this to see it in actions*/
Example 2: initialising 2d vector
// Initializing 2D vector "vect" with
// values
vector > vect{ { 1, 2, 3 },
{ 4, 5, 6 },
{ 7, 8, 9 } };
Example 3: how to take input in 2d vector in c++
std::vector> d;
//std::vector d;
cout<<"Enter the N number of ship and port:"<>in;
cout<<"\Enter preference etc..:\n";
for(i=0; i>temp;
d[i].push_back(temp);
}
}
Example 4: how to take input in 2d vector in c++
std::vector> d;
//std::vector d;
cout<<"Enter the N number of ship and port:"<>in;
cout<<"\Enter preference etc..:\n";
for(i=0; i>temp;
d.push_back(temp);// I don't know how to push_back here!!
}
}
Example 5: input 2d vector c++
vector > d;
int val;
for(int i = 0; i < in; i++){
vector temp;
for(int j = 0; j < in; j++){
cin >> val;
temp.push_back(val);
}
d.push_back(temp);
temp.clear();
}
Example 6: input 2d vector c++
vector > d;
int val;
for(int i = 0; i < in; i++){
vector temp;
for(int j = 0; j < in; j++){
cin >> val;
temp.push_back(val);
}
d.push_back(temp);
temp.clear();
}
From SpyrosD3v25