Vectors in C++

Discussion in 'Programming/Html' started by Ghosty, Jun 6, 2020.

  1. Ghosty

    Ghosty Ancient Guru

    Messages:
    7,670
    Likes Received:
    970
    GPU:
    RTX 3050
    Vectors. Where to start.... Strings are pretty easy to get to grips with. Vectors on the other hand require a lot of work to understand and implement correctly. Add algorithms to the mix, and you have a very complexed piece of code. I like it!

    Anyone tried vectors yet?
     
  2. pattakosn

    pattakosn Member

    Messages:
    27
    Likes Received:
    17
    GPU:
    RX 570 4Gb
    do you mean std::vector? Most likely it is the most used c++ container. Is there sth in particular you would like to ask? BTW, algorithms are not limited to vector containers, they can also be used eg for strings.
     
  3. Ghosty

    Ghosty Ancient Guru

    Messages:
    7,670
    Likes Received:
    970
    GPU:
    RTX 3050
    std::vector or #include. I guess it depends on what you are used to using.
     
  4. pattakosn

    pattakosn Member

    Messages:
    27
    Likes Received:
    17
    GPU:
    RX 570 4Gb
    Is there a question that you would like to ask or are we simply chatting?
     

  5. Ghosty

    Ghosty Ancient Guru

    Messages:
    7,670
    Likes Received:
    970
    GPU:
    RTX 3050
    Yeah. Which is better to use in 2020. Strings or vectors? I know strings offer better memory scaling for smaller stuff. Vectors are more complicated to learn but seem offer more choice and flexibility. I've used both so far, and was just wondering.
     
  6. pattakosn

    pattakosn Member

    Messages:
    27
    Likes Received:
    17
    GPU:
    RX 570 4Gb
    Use string for strings (ie character arrays) and vectors for dynamically sized arrays (ie whose size may change during their lifetime) of anything else.
     
  7. Ghosty

    Ghosty Ancient Guru

    Messages:
    7,670
    Likes Received:
    970
    GPU:
    RTX 3050
    I don't really understand how vectors differs from strings. Both can be modded at any point to add more if needed. If anything strings apoear easier to do that with. But, I've only strached the surface of vectors so far.
     
  8. pattakosn

    pattakosn Member

    Messages:
    27
    Likes Received:
    17
    GPU:
    RX 570 4Gb
    Do you know the difference between character arrays and int,double,struct/class ? If you do, use string for char and vector for the rest.
     
    Ghosty likes this.

Share This Page