title: vector string push_back is not working in c++
body: <p>This code snippet receives string, delimiter(space) and vector as argument and splits the string according to delimiter and stores it in vector. It is not storing anything into vector if i use push_back but works if i use [] operator. Can someone explain why push_back is not working?</p>
  
  <pre><code>void split(const string &amp; input,char delim,vector&lt;string&gt; &amp; elems){
      stringstream  ss;
      ss.str(input);
      string item;
      int i = 0;
      while(getline(ss,item,delim)){
          //elems.push_back(item);
          elems[i] = item;
          i++;
      }
  }
  
  int main(){
     char delim = ' ';
     vector&lt;string&gt; item(2);
     string input;
     getline(cin,input);
     split(input,delim,item);
  }
  </code></pre>