title: Initialize vector to zero
body: <p>Initially the vector "perm" is null. I want to set it to zero based on the index of the loop. But i have encounter error "vector subscript out of range" while doing the below code. </p>
  
  <p>I placed "perm(charLength, 0)" in the "Start()" method outside of any loop so that it will not be reset, it's used for accumulating values.</p>
  
  <p>DecodeEngine.h</p>
  
  <pre><code>class DecodeEngine
  {
  
  public:
  
      vector&lt;int&gt; temp;
      vector&lt;int&gt; perm;
  
      //Default constructor
      DecodeEngine();
  
  
      //Declare a virtual destructor:
      virtual ~DecodeEngine();
  
      //Methods
      string GetFilePath();
      Mat Start();
      void FrameTo8by8();         
  };
  </code></pre>
  
  <p>DecodeEngine.cpp</p>
  
  <pre><code>Mat DecodeEngine::Start()
  {
    charLength = 160;
  
    //Initialize perm to zero
    perm(charLength, 0);
  
    //Loop 1st 100 frame of header
    while(true)
    {
       if(frame_count &lt;= 100)
       {
          FrameTo8by8();                  //Proccess and algorithm
  
          namedWindow("dctBlockImage"); 
          imshow("dctBlockImage", dctImage);      //display watermarked image
  
          if(waitKey(30) == 27) //wait for 'esc' key press for 30 ms. If 'esc' key is pressed, break loop
          {
              cout &lt;&lt; "esc key is pressed by user" &lt;&lt; endl; 
              break; 
          }
  
          frame_count++;
       }
  
       else
       {
          cout &lt;&lt; endl;
          cout &lt;&lt; "End of video" &lt;&lt; endl;
          cout &lt;&lt; endl;
  
          destroyWindow("Original Video");
          destroyWindow("dctBlockImage");
          break;
       }
  }
  
  
  
  
  void DecodeEngine::FrameTo8by8()
  {
    for(int i = 0; i &lt; height-16; i += 16)
    {
      for(int j = 0 ; j &lt; width-16; j += 16)
      {
         if(j &gt; 112)
         {
             if(((sum4 / 4) - avg) &gt; 0)
             {
                value = 0;
                temp.push_back(value);
             }
  
             else
             {
                value = 1;
                temp.push_back(value);
             }
         }
  
         if(temp.size() == charLength)
         {
            for(int a = 0; a &lt;= temp.size(); a ++)
            {
               //Initialize perm to zero
               perm[a] = 0;
  
               if(temp[a] == 1)
               {
                  perm[a]++;
               }
  
               //Reset temp for next frame to use
               temp[a] = 0;
            }
         }                
  
      }
    }
  }
  </code></pre>