title: How to get my CSV File reader to read different types in C++?
body: <p>For my project, my program has to read a file that looks like this: "Mary", "000111222", "Junior", 12, 4.0
  In my main code it can read it, but only as strings only. I want it to read it as string,string, string, float, float. The getLine() method only works with strings. I tried other ways but it did not work. Any suggestions? The fields I want to be a float is gpa and credit. Any advice is appreciated! Thank you!</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;string&gt;
  #include &lt;iterator&gt;
  #include &lt;iomanip&gt;
  #include &lt;fstream&gt;
  #include &lt;vector&gt;
  include &lt;sstream&gt;
  #include &lt;algorithm&gt;
  
  
  using namespace std;
  
  class Student {
  
    //declare local variables
    protected:
  string name;    //people with names longer than 21 characters will just have 
                    to make do
  string ssn;     // Social Secturity Number. 
  string gpa;     //Most up to date gpa for the student
  string credits; //Number of student's credit hours
  
                  //build public methods
  public:
  
  //Default Constructor
  Student() {}
  
  
   //Student constructor. Besides the character arrays, everything else is 
   passed by reference.
    Student(const string n, const string s, string sGPA, string sCredits) {
  
      name = n;
      ssn = s;
      gpa = sGPA;
      credits = sCredits;
  }
  string getName() {
      return name;
  }
  string getSSN() {
      return ssn;
  }
  string getGPA() {
      return gpa;
  }
  string getCredit() {
      return credits;
  }
  //a function that is expected to be implemented and overridden by subclasses
  virtual void print() const {
  
      cout &lt;&lt; '\n' &lt;&lt; endl;
      cout &lt;&lt; "Student's name: " &lt;&lt; name &lt;&lt; endl;
      cout &lt;&lt; "Student SSN: " &lt;&lt; ssn &lt;&lt; endl;
      cout &lt;&lt; "Student's current GPA: " &lt;&lt; gpa &lt;&lt; endl;
      cout &lt;&lt; "Student's credit hours: " &lt;&lt; credits &lt;&lt; endl;
    }
  
  
  // a pure virtual function for implementation later. Makes whole class 
  Abstract
  virtual float tuition() const = 0;
   };
  
    class Undergrad : public Student {
  
  //declare local variables
  
    protected:
    float undergrad_rate = 380.0;
    string year;
  
  
    //build public methods
  
    public:
  
   //Default Constructor
   Undergrad() {}
  
  
  //Undergrad Constructor
   Undergrad(const string n, const string s, string uGPA, string uCredits, 
   string y) :
      Student(n, s, uGPA, uCredits), year(y) {}
  
  
  //Display the contents of undergrad
  void print() const {
      Student::print();
      cout &lt;&lt; "Undergrad Rate: " &lt;&lt; undergrad_rate &lt;&lt; endl;
      cout &lt;&lt; "Year: " &lt;&lt; year &lt;&lt; endl;
  }
  
  
  //Display undergrad's current year
  string get_year() {
      return year;
  }
  
  
  //Display the undergrad's current rate
  float get_rate() {
      return undergrad_rate;
  }
  
  
  //Set a undergrad's current year
  void set_year(string y) {
      year = y;
  }
  
  
  //Display the cost for an undergrad to attend university
  float tuition() const {
      return 1000000;
  }
  };
  
  
  
  int main() {
  ifstream ip("data.txt");
  
  if (!ip.is_open()) std::cout &lt;&lt; "ERROR: File not found" &lt;&lt; '/n';
  string name;
  string ssn;
  string year;
  string credit;
  string gpa;
  
  vector&lt;Undergrad&gt; file;
  //Undergrad g(name, ssn, year, credit, gpa);
  while (ip.good()) {
      getline(ip, name, ',');
      getline(ip, ssn, ',');
      getline(ip, gpa, ',');
      getline(ip, credit, ',');
      getline(ip, year, '\n');
  
      //  float number = stoi(gpa);
      //float number1 = stoi(credit);
      Undergrad g(name, ssn, year, credit, gpa);
      file.push_back(g);
  
  
  
  
  
  
  
  }
  ip.close();
  Undergrad g = file.back();
  file.pop_back();
  file.insert(file.begin(),g);
  
  
  
  for (int i = 0; i &lt; file.size(); i++) {
      cout &lt;&lt; "Name: " &lt;&lt; file[i].getName() &lt;&lt; endl;
      cout &lt;&lt; "SSN: " &lt;&lt; file[i].getSSN() &lt;&lt; endl;
      cout &lt;&lt; "Year: " &lt;&lt; file[i].get_year() &lt;&lt; endl;
      cout &lt;&lt; "Credit:  " &lt;&lt; file[i].getCredit() &lt;&lt; endl;
      cout &lt;&lt; "GPA " &lt;&lt; file[i].getGPA() &lt;&lt; endl;
      cout &lt;&lt; " " &lt;&lt; endl;
  
  
  }
  
  
  
  system("pause");
  return 0;
  </code></pre>
  
  <p>}</p>