| noktalivirgul (41) | |
|
Hi; I want to fill a 2D vector by some floats. can i use list.push_back again? How?for example I want to send 4.5 to the ithrow and jth column. | |
|
Last edited on
|
|
| SuperSonic (64) | |
If you want to push back something to the ith row then use this:my_vector[i].push_back(4.5);However, if you just want to assign 4.5 to the ith row and jth column, then do this: my_vector[i][j] = 4.5;
| |
|
|
|
| noktalivirgul (41) | |
How do i define my vector if i use it in this way?? 1D or 2D?my_vector[i].push_back(4.5);does this line show in which column 4.5 is?? | |
|
|
|
| Stewbond (1670) | |||||
lets say you want a matrix like this:
Just construct your rows, one at a time, then push them into the 2D vector like so:
I like to use the Typedef when doing this because it makes it very clear that we have a vector of rows. std::vector< std::vector<int> > is too verbose for me.
| |||||
|
Last edited on
|
|||||