6

Getting hard time to understand std::vector and even more confusing with multidimensional vector.
Going back to array. 😪

Comments
  • 0
    Why? STL FTW
  • 0
    Well you just create a vector like vector<type you want> a; then you can put data into it with push_back(data with type you gave before); you can add almost as much data as you want with that method. You can access it like an array a[0] is its first element like in a standard array. Well you also have a size() function which will return its length. For each can be done in multiple ways like with good old array you can go though until size, you can have range fors, and here also iterators. Well if you want one with a given size you can resize(new length) it. You can create multi dimension ones like vector<vector<int>> b; then you can push vector<int> into b the same way.
  • 0
    Go visit learncpp.com . It's an amazing site that taught me C++ quite well. It's up to date, and it does not contain terrible code samples like many other such sites do.

    More importantly for you, I believe it has a pretty good section on std::vector as well ☺

    Edit: the exact link: http://learncpp.com/cpp-tutorial/...
  • 0
    This is the first time I handle std::vector and I'm using orange pi, and I don't really understand how set compiler to c++11, default is c++98.
    In c++98 you can't initialize value to vector just like array. Only initialize size and default value. Do I need to pushback manually?

    So I change the little library that I found, change it to using double pointer (**) instead. Hha 😌

    Yeah, I think it worth to learn it. Thanks guys
Add Comment