title: Looking to add comma delimited values in a text file to members of a class
body: <p>I created a post here last week but it was for a struct. </p>
  
  <p><a href="https://stackoverflow.com/questions/55472561/looking-to-add-comma-delimited-values-in-a-text-file-to-members-of-a-struct/55473123#55473123">Looking to add comma delimited values in a text file to members of a struct</a></p>
  
  <p>I have a text file here with two values, a name and a score. I have a student class that has 4 members which are seen below.</p>
  
  <p>I am looking to add the values in the text file to the corresponding members in the class separating by comma.</p>
  
  <p>First five rows of the students.txt file;</p>
  
  <pre><code>Nubia,Dufrene,70
  Louisa,Trippe,49
  Aline,Deniz,34
  Shery,Munk,63
  Angila,Ping,89
  </code></pre>
  
  <p>My current code;</p>
  
  <p><strong>studentType.h</strong></p>
  
  <pre><code>class q1studentType
  {
      //Private Memebrs
      std::string studentFName;
      std::string studentLName;
      std::string testScore;
      char grade;
  
  
  public:
      //Constructor
      q1studentType(std::string studentFName,std::string studentLName, std::string testScore);
  
      //Get &amp; Set
      std::string const getStudentFName() { return studentFName; }
      std::string const getStudentLName() { return studentLName; }
      std::string getTestScore() const { return testScore; }
  
      void setStudentFName(std::string fN) { q1studentType::studentFName = fN; }
      void setStudentLName(std::string lN) { q1studentType::studentLName = lN; }
      void setTestScore(std::string ts) { q1studentType::testScore = ts; }
  
      //Member Functions
      void printStudent();
      int stringToInt(std::string convertMe);
      //std::vector&lt;q1studentType&gt; initStudents();
  
      ~q1studentType();
  };
  </code></pre>
  
  <p><strong>studentType.cpp</strong></p>
  
  <pre><code>q1studentType::q1studentType(std::string sFN, std::string sLN, std::string ts)
  {
      studentFName = sFN;
      studentLName = sLN;
      testScore = ts;
      stringToInt(testScore);
      //assignGrade();
  }
  </code></pre>
  
  <p><strong>main.cpp</strong></p>
  
  <pre><code>void initstudents() {
      std::vector&lt;q1studentType&gt; students;
      std::ifstream inFile("students.txt");
  
      for (q1studentType i;
          getline(inFile, i.setStudentFName, ',')
          &amp;&amp; getline(inFile, i.setStudentLName, ',')
          &amp;&amp; getline(inFile, i.setTestScore)
          ; )
      {
          studentVector.push_back(i);
      }
  }
  </code></pre>
  
  <p>I think the function in the main does not work because getline doesnt accept the setMethod as a param.
  I cant use the class members in the for loop eg. i.studentFName because they are private and only accessible inside the class.</p>
  
  <p>What is the best approach? Should I have the initstudents in the student.cpp file or the main? </p>