Category : 2d-vector

I am trying to create a 10 by 10 grid with uint8_t values. using some coordinates I am trying to place 255 values at those indexes. When I substitute 255 at those coordinates it works fine but as soon as I try to print out the values at those indexes it doesn’t seem to be ..

Read more

I was creating empty 2D vector in a header file by just providing size but unable to create it. class Grid { public: int rows = 5/0.05; int cols = 6/0.05; std::vector<std::vector<uint8_t>> grid(rows, std::vector<uint8_t>(cols, 0)); }; I am getting below error no matching function for call to ‘std::vector<std::vector >::vector(int&, std::vector)’ error: ‘rows’ is not a ..

Read more

I have a simple ball class. It takes a color name for its initialization. Ball::Ball(ColorName color_name) : m_color_name{color_name} { } I try to create a 2d-vector board to contain some balls. The width and the height are given outside. class Board { private: int m_width; int m_height; std::vector<std::vector<Ball>> m_grids; public: Board(int width, int height); ~Board(); ..

Read more

I am trying to take values in a 2d vector called alloc from the user but the alloc zero index is the only changed index and the values of each index override it i don’t know why (i.e: only the first index of the 2d vector is affected) Code: cout<<"Please Enter n"<<endl; cin>>n; cout<<"Please Enter ..

Read more

let’s say I have a vector storing vectors of strings. std::vector<std::vector<std::string>> MyVec = { {}, {} } I want to use anything equivalent to .push_back(X) such that the vector will now look as following: { {X}, {} }. Does anyone have an idea for a way to solve this? Source: Windows Que..

Read more