title: C++ is there a way to resize a vector to specific character?
body: <p>Basically I have a vector that contains bits of binary and I want to resize the vector to be only the length of the useful info. The length of the Vector Is very large since it is holding user input, And I could not find a way to make the vector's length dynamic to the length of the users input.</p>
  
  <p>so the vectors contents would essentially be ~
  1001101010100110010110100000000000000000000000000000000</p>
  
  <p>is there a way to shrink the vector to:
  10011010101001100101101</p>
  
  <pre><code>myVector.shrink_to_fit();
  </code></pre>
  
  <p>doesn't solve my problem because the vector is populated with null data.</p>
  
  <pre><code>//Included Libraries
  #include "stdafx.h"
  #include &lt;iostream&gt;
  #include &lt;string&gt;
  #include &lt;vector&gt;
  
  
  using namespace std;
  
                               // Var Declerations
  string inputText;
  std::vector&lt;int&gt; ba; //ba=binary array* originally was an array
  
  
  void displayBinaryVector()
  {
      for (int i = 0; i &lt; ba.size(); i=i+8)
      {
          cout &lt;&lt; ba.at(i) &lt;&lt; ba.at(i+1) &lt;&lt; ba.at(i+2) &lt;&lt; ba.at(i+3) &lt;&lt; ba.at(i+4) &lt;&lt; ba.at(i+5) &lt;&lt; ba.at(i+6) &lt;&lt; ba.at(i+7) &lt;&lt; endl;
      }
  }
  
  //Main Function
  int main()
  {
  
      // Gets input
      cout &lt;&lt; "Please Enter What You Would Like To Be Encoded" &lt;&lt; endl;
      getline(cin, inputText);
      ba.resize((128*8));
      convertToBinary();
      displayBinaryVector();
      return 0;
  }
  </code></pre>
  
  <p>** edit **  clarified code (I think) and updated to my current solution.</p>
  
  <p>I Think I have found A solution that works for my particular situation:</p>
  
  <pre><code>void displayBinaryVector()
  {
  for (int i = 0; i &lt; ba.size();)
  {
      cout &lt;&lt; ba.at(i) &lt;&lt; ba.at(i+1) &lt;&lt; ba.at(i+2) &lt;&lt; ba.at(i+3) &lt;&lt; ba.at(i+4)     &lt;&lt; ba.at(i+5) &lt;&lt; ba.at(i+6) &lt;&lt; ba.at(i+7) &lt;&lt; endl;
      i = i + 8;
      if ((ba.at(i) + ba.at(i + 1) + ba.at(i + 2) + ba.at(i + 3) + ba.at(i +   4) + ba.at(i + 5) + ba.at(i + 6) + ba.at(i + 7)) == 0)
      {
          ba.resize(i);
      }
  }
  }
  </code></pre>
  
  <p>I am still curious if there is a method or pre-written function that you can call that would essentially be reversing the vector searching until specified value/values are found and deleting any elements that have been 'checked'.</p>