• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 378
  • Last Modified:

C++ Vectors and STL

Hi,

Can anyone please give me an example of how can I use the STL to create a vector ?

I would like to see examples of insert and remove from the vector.

Tnx
0
BaneBane
Asked:
BaneBane
  • 2
1 Solution
 
chensuCommented:
vector (Every member function comes with a sample.)
http://msdn.microsoft.com/visualc/stl/vector.htm
0
 
SridharReddyCommented:

  #include <vector>
  #include <algorithm>
 
  using namespace std;

  class myClass{
 
      public:
      // overload operator <
      // overload operator ==
//NOTE:
// If you have char* as members, overload the copy and assignment operators as well. This is a must !
Else use string from <string> of Standard library and be carefree :)
  };


typedef vector<myClass>  MyVector;

  int main()
  {
  MyVector MyCollection;
 
      while(//there is data input )
      {
            myClass object;
            object.addData();
            MyCollection.push_back(object);
      }
      // collection is poupulated here.
      // start using it.

  return 0;
 }
0

Featured Post

Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now