title: Deleting an element from a vector
body: <p>I am new to C++ and I am writing a program that is supposed to simulate a colony of bunnies. The program will be able to add them, give them names, ages, colors, etc. Right now I have a working program that will add bunnies after each pass and age them by 1. How could I make the program delete a bunny once the bunny reaches age 10.</p>
  
  <p>The code:</p>
  
  <pre><code>enter code here
  #include &lt;iostream&gt;
  #include &lt;ctime&gt;
  #include &lt;vector&gt;
  #include &lt;cstdlib&gt;
  #include &lt;limits&gt;
  
  using namespace std;
  
  const int  POSSIBLE_NAMES = 18;
  const int  POSSIBLE_COLORS = 4;
  
  static std::string possibleNames[] ={
      "Jen",
      "Alex",
      "Janice",
      "Tom",
      "Bob",
      "Cassie",
      "Louis",
      "Frank",
      "Bugs",
      "Daffy",
      "Mickey",
      "Minnie",
      "Pluto",
      "Venus",
      "Topanga",
      "Corey",
      "Francis",
      "London",
  };
  static std::string possibleColors[] ={
  
      "White",
      "Brown",
      "Black",
      "Spotted"
  };
  
  struct Bunny
  {
  public:
  
  string name;
  int age;
  string color;
  char sex;
  
  Bunny(){
      setSex();
      setColor();
      setAge(0);
      setName();
  }
  
  int randomGeneration(int x){
      return rand() % x;
      srand (time(NULL));
  }
  
  void setSex()
  {
      int randomNumber = randomGeneration(2);
      ( randomNumber == 1 ) ? sex = 'm' : sex = 'f';
  }
  
  char getSex()
  {
      return sex;
  }
  
  void setColor()
  {
      int randomNumber = randomGeneration(POSSIBLE_COLORS);
      color = possibleColors[randomNumber];
  }
  
  string getColor()
  {
      return color;
  }
  
  void setAge(int age)
  {
      this-&gt;age = age;
  }
  
  int getAge()
  {
      age++;
      return age;
  }
  
  void setName()
  {
      int i = randomGeneration(POSSIBLE_NAMES);
      name = possibleNames[i];
  }
  
  string getName()
  {
      return name;
  }
  
  void deleteBunny(){
      if (age &gt; 10){
          cout &lt;&lt; getName() &lt;&lt; " has died" &lt;&lt; endl;
      }
  }
  void printBunny()
  {
      cout &lt;&lt; "Name: " &lt;&lt; getName() &lt;&lt; endl;
      cout &lt;&lt; "Sex: " &lt;&lt; getSex() &lt;&lt; endl;
      cout &lt;&lt; "Color: " &lt;&lt; getColor() &lt;&lt; endl;
      cout &lt;&lt; "Age: " &lt;&lt; getAge() &lt;&lt; endl;
  }
  };
  
  int main()
  {
     vector&lt; Bunny &gt; colony;
     char quit = '\0';
     do
     {
        // Add more bunny
        for (int i = 0; i &lt; 5; i++)
        {
           colony.push_back(Bunny());
        }
        // Print all the bunny
        for (int i =0; i &lt; colony.size(); i++)
        {
           colony[i].printBunny();
           colony[i].deleteBunny();
           cout &lt;&lt; endl;
        }
        cout &lt;&lt; "You have a total of " &lt;&lt; colony.size() &lt;&lt; " bunnies\n";
        cout &lt;&lt; "Press a key to add more bunny, q to quit\n";
        quit = cin.get();
        cin.ignore(std::numeric_limits&lt;std::streamsize&gt;::max(), '\n');
         // repeat
     } while (quit != 'q' &amp;&amp; quit != 'Q');
  
     return 0;
  }
  </code></pre>