title: How do I read comma and quotation delimited file in C++?
body: <p>The file has</p>
  <pre><code>CompanyNo, Items baught (3 from every company), totalpaid, totalreturn(due to bad product), relation with other company(if any(companyNo))
  
  a787, apple, banana, strawberry, &quot;32,888.00&quot;, &quot;0.0&quot; k798, g456
  f238, &quot;Orange, Juice&quot;, Kiwi, &quot;20,666.03&quot;, 0.0
  g456, &quot;Fresh, Beef&quot;, Lamb, Chicken, &quot;40,500.00&quot;, &quot;4,134.00&quot;, f238
  </code></pre>
  <p>and so on
  I am trying to read it into a class</p>
  <pre><code>class Company {
  
      std::string CompanyNo;
      std::string Item1;
      std::string Item2;
      std::string Item3;
      double Paid;
      double Return;
      vector&lt;std::string&gt; RelatedTo;
  
  public:
  
      Company(std::string CompanyNo, std::string Item1, std::string Item2, std::string Item3, double paid, double Return, std::vector&lt;std::string&gt; RelatedTo)
      {
          this-&gt;CompanyNo = CompanyNo;
          this-&gt;Item1 = Item1;
          this-&gt;Item2 = Item2;
          this-&gt;Item3 = Item3;
          this-&gt;Paid = Paid;
          this-&gt;Return = Return;
          this-&gt;RelatedTo = RelatedTo;
      };
  
      ~Client() {};
  
      Company(const Company&amp; cn) {
          this-&gt;CompanyNo = cn.CompanyNo;
          this-&gt;Item1 = cn.Item1;
          this-&gt;Item2 = cn.Item2;
          this-&gt;Item3 = cn.Item3;
          this-&gt;Paid = cn.Paid;
          this-&gt;Return = cn.Return;
          this-&gt;RelatedTo = cn.RelatedTo;
      };
  
      Company() {};
  
      Company operator= (Company cn) {
          this-&gt;CompanyNo = cn.CompanyNo;
          this-&gt;Item1 = cn.Item1;
          this-&gt;Item2 = cn.Item2;
          this-&gt;Item3 = cn.Item3;
          this-&gt;Paid = cn.Paid;
          this-&gt;Return = cn.Return;
          this-&gt;RelatedTo = cn.RelatedTo;
          return cn;
      }
  
      void setCompanyNo(std::string i) { CompanyNo = i; };
      void setItem1(std::string i1) { Item1 = i1; };
      void setItem2(std::string i2) { Item2 = i2; };
      void setItem3(std::string i3) { Item3 = i3; };
      void setPaid(double p) {Paid = p; };
      void setReturn(double r) { Return = r; };
      void setRelatedTo(std::vector&lt;std::string&gt; rt) { RelatedTo = rt; }
  
  
      std::string getCompanyNo() const { return CompanyNo; }
      std::string getItem1() const { return Item1; }
      std::string getItem2() const { return Item2; }
      std::string getItem3() const { return Item3; }
      double getPaid() const { return Paid; }
      double getReturn() const { return Return; }
      vector&lt;std::string&gt; getRelatedTo() const { return RelatedTo; }
  
  };
  </code></pre>
  <p>At the bottom is what I have tried but doesn't really store each value into the class. This is my first time reading complicated file with different number of columns and commas between strings and doubles like &quot;32,888.00&quot; should store like 32888.00 in class and through file is comma delimited items like &quot;orange, juice&quot; should store like orange, juice rather then orange and juice separately. And relation to other should store as vector since company can have relation with many companies or non. Any help would be appreciated thank you</p>
  <pre><code>vector &lt;Company&gt; Info;
  
  Company parseLine(string str)
  {
      vector&lt;string&gt; store;
      string tok;
      stringstream evaluator;
      Company retv;
  
      evaluator &lt;&lt; str;
      {
          char double_quote_remover;
          evaluator &gt;&gt; double_quote_remover; 
          getline(evaluator, tok, '&quot;'); 
          char comma_remover;
          evaluator &gt;&gt; comma_remover; 
      }
  
      char ch;
  
      while (evaluator &gt;&gt; ch &amp;&amp; ch != ','); 
  
      tok = &quot;&quot;; 
      ch = ' '; 
  
      while (evaluator &gt;&gt; ch) {  
          if (isalpha(ch)) { evaluator.putback(ch); ch = ','; } 
          if (ch == '\&quot;') getline(evaluator, tok, '\&quot;'); 
          else if (ch == ',') getline(evaluator, tok, ','); 
              store.push_back(tok);
          tok = &quot;&quot;; 
      }
  
      retv.setRelatedTo(store); 
  
      return retv; 
  
  }
  
  bool readFile()
  {
      std::ifstream myFile(&quot;Data.txt&quot;);
      if (!myFile.is_open())
      {
          cout &lt;&lt; &quot;FAILED&quot; &lt;&lt; &quot;\n&quot;;
          return false;
      }
      string str;
  
      getline(myFile, str); 
  
      int i = 0;
      while (std::getline(myFile, str))
      {
          Company Company = parseLine(str);
          Info.push_back(Company);
      }
      return true;
  }
  
  int main()
  {
      bool data = readFile();
  
  }
  </code></pre>