I am trying to create a 2-D vector that as column 0 it would have integers and column 1 would have vectors.
For example:
column[0] column[1]
2 {2}
5 {1,2,0}
12 {4,7,9,0,0,1,6,0,0}
3 {6}
column 0 would be user input while column 1 I will calculate it on my own - I don't mind if it has dummy vectors for now and after the user exits then it would print the 2-D vector. What I tried is:
int main() {
unsigned int input;
vector<vector<unsigned int>> v;
while (cin >> input) // enter non int to exit
for(int i=0; i<input;i++){
vector<int> factorial; //calc in a separate function - dummy vector for now
for (int j=0; j<factorial.size(); j++){
v[i].push_back(input); //set column 0 as input
v[i][j].push_back(factorial); //set column 1 as the vector containing the factorial of input
}
}
return 0;
}
Seems like you need to use
class
:But, if you need more shortest implementations, you can use
map
:So in "
map
" case, output should be like this:Otherwise, you can just use 2 different arrays or
vectors
:Maybe, it's the best option for you now.
And if you work with
int
only, you can changeFactorialNumbers
like this:You can also try:
vector<pair<int, std::vector<int>>>