Jump to content

C++ Vectors

- - - - -

  • Please log in to reply
8 replies to this topic

#1
hetra

hetra

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 297 posts
  • Location:Australia
  • Programming Language:C, C++, PHP, Python, Delphi/Object Pascal, Assembly
  • Learning:Python, Assembly
Hello All,

Are C++ vectors the same as the vectors in maths?

A vector has a size and magnitude, is a C++ vector like this? I had some trouble with C++ vectors and the ideas behind them.

Thanks.

#2
opwuaioc

opwuaioc

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 216 posts
Vectors are like arrays. If you haven't already looked at this, it contains code too. C++ Reference - vector
Something witty here.

#3
hetra

hetra

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 297 posts
  • Location:Australia
  • Programming Language:C, C++, PHP, Python, Delphi/Object Pascal, Assembly
  • Learning:Python, Assembly
So it's not like the vectors in mathematics? (Size and magnitude-e.g. Speed).

#4
Alexander

Alexander

    It's Science!

  • Moderators
  • 4,118 posts
  • Location:Vancouver, Eh! Cleverness: 200

Hunter100 said:

So it's not like the vectors in mathematics? (Size and magnitude-e.g. Speed).

Nope, There are such things as synonyms you know.

Regardless, In the English language; vector: a variable quantity that can be resolved into components.
Be sure to read the updated FAQ! || Health is achieved through the same 10,000 steps.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.

#5
hetra

hetra

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 297 posts
  • Location:Australia
  • Programming Language:C, C++, PHP, Python, Delphi/Object Pascal, Assembly
  • Learning:Python, Assembly
Oh okay thanks again nullw0rm your really helpful.

#6
Muted

Muted

    Learning Programmer

  • Members
  • PipPipPip
  • 86 posts

Quote

Vectors are like arrays. If you haven't already looked at this, it contains code too. C++ Reference - vector

A vector in C++ is only a container. A vector can contain any data type. Vector's are apart of the STL (Standard Template Library).
A vector has predefined methods (functions) which can operate on the data, which make it very useful in some cases.

Unlike predefined arrays, vector's are dynamic, which means they can grow, or shrink as needed.
There are many more benefits to using vectors over arrays in certain cases; Not that you shouldn't ever use an array.
“You may be disappointed if you fail, but you are doomed if you don't try.”
- Beverly Sills

#7
opwuaioc

opwuaioc

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 216 posts

Muted said:

A vector in C++ is only a container. A vector can contain any data type. Vector's are apart of the STL (Standard Template Library).
A vector has predefined methods (functions) which can operate on the data, which make it very useful in some cases.

Unlike predefined arrays, vector's are dynamic, which means they can grow, or shrink as needed.
There are many more benefits to using vectors over arrays in certain cases; Not that you shouldn't ever use an array.

That's why I said "like arrays". :)
Something witty here.

#8
hetra

hetra

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 297 posts
  • Location:Australia
  • Programming Language:C, C++, PHP, Python, Delphi/Object Pascal, Assembly
  • Learning:Python, Assembly
Oh, so they can be resized as needed, but is that dependent upon the amount of data inputted or just the programmer?

#9
Muted

Muted

    Learning Programmer

  • Members
  • PipPipPip
  • 86 posts

Hunter100 said:

Oh, so they can be resized as needed, but is that dependent upon the amount of data inputted or just the programmer?

No, it is not dependent upon the 'amount of data inputted.'
You can set the vectors size to an exact specification if you wish.

Link: resize - C++ Reference
“You may be disappointed if you fail, but you are doomed if you don't try.”
- Beverly Sills




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users