Vectors in C++

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

  1. Ghosty

    Ghosty Ancient Guru

    Messages:
    5,239
    Likes Received:
    78
    GPU:
    3200U
    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:
    14
    Likes Received:
    4
    GPU:
    970gtx
    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:
    5,239
    Likes Received:
    78
    GPU:
    3200U
    std::vector or #include. I guess it depends on what you are used to using.
     
  4. pattakosn

    pattakosn Member

    Messages:
    14
    Likes Received:
    4
    GPU:
    970gtx
    Is there a question that you would like to ask or are we simply chatting?
     

  5. Ghosty

    Ghosty Ancient Guru

    Messages:
    5,239
    Likes Received:
    78
    GPU:
    3200U
    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:
    14
    Likes Received:
    4
    GPU:
    970gtx
    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:
    5,239
    Likes Received:
    78
    GPU:
    3200U
    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:
    14
    Likes Received:
    4
    GPU:
    970gtx
    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