title: Vector of structs initialization
body: <p>I want know how I can add values to my vector of structs using the <code>push_back</code> method</p>
  
  <pre><code>struct subject
  {
    string name;
    int marks;
    int credits;
  };
  
  
  vector&lt;subject&gt; sub;
  </code></pre>
  
  <p>So now how can I add elements to it?</p>
  
  <p>I have function that initializes string name(subject name to it)</p>
  
  <pre><code>void setName(string s1, string s2, ...... string s6)
  {
     // how can i set name too sub[0].name= "english", sub[1].name = "math" etc
  
    sub[0].name = s1 // gives segmentation fault; so how do I use push_back method?
  
    sub.name.push_back(s1);
    sub.name.push_back(s2);
    sub.name.push_back(s3);
    sub.name.push_back(s4);
  
    sub.name.push_back(s6);
  
  }
  </code></pre>
  
  <p>Function call</p>
  
  <pre><code>setName("english", "math", "physics" ... "economics");
  </code></pre>