title: Why am I getting error messages in my "customer.cpp" file
body: <p>I am unsure about why I am getting this error message when I hover over <code>purchaseArray</code> in my <code>string Customer::save()</code> method in the <code>customer.cpp</code> file:</p>
  <blockquote>
  <p>identifier is undefined</p>
  </blockquote>
  <p>And this error message when I hover over <code>getline</code> in the <code>void Customer::parse(string line)</code> method in the <code>customer.cpp</code> file:</p>
  <blockquote>
  <p>no instance of overloaded function &quot;getline&quot; matches the argument list argument types are: (std::stringstream, int, char)</p>
  </blockquote>
  <p>Code in the <code>Customer.cpp</code> file:</p>
  <pre><code>#include &quot;Customer.h&quot;
  #include &lt;iostream&gt;
  #include &lt;string&gt;
  #include &lt;fstream&gt;
  #include &lt;sstream&gt;
  #include&lt;utility&gt;
  using namespace std;
  
  //default constructor
  Customer::Customer() {
  }
  
  
  //Full constructor
  Customer::Customer(int customerID, string title, string name, int numOfPurchases, int purchase1, int purchase2, int purchase3, string type)
  {
      this-&gt;customerID = customerID;
      this-&gt;title = title;
      this-&gt;name = name;
      this-&gt;numOfPurchases = numOfPurchases;
      purchases = new int[3];
      purchases[0] = purchase1;
      purchases[1] = purchase2;
      purchases[2] = purchase3;
      this-&gt;type = type;
  }
  
  Customer::Customer(const Customer&amp; source) //copy constructor
  {
      cout &lt;&lt; &quot;copy constructor called&quot; &lt;&lt; endl;
      this-&gt;customerID = source.customerID;
      this-&gt;title = source.title;
      this-&gt;name = source.name;
      this-&gt;numOfPurchases = source.numOfPurchases;
      this-&gt;purchases = new int[3];
      purchases[0] = source.purchases[0];
      purchases[1] = source.purchases[1];
      purchases[2] = source.purchases[2];
      this-&gt;type = source.type;
  }
  
  //overloaded assignment operator=
  Customer&amp; Customer::operator= (Customer&amp; otherCustomer)
  {
      cout &lt;&lt; &quot;Overloaded assignment operator= called&quot; &lt;&lt; endl;
  
      //self-assignment guard
      if (this == &amp;otherCustomer)
          return *this;  //refernce to the same object
  
     // copy data from the source (rhs) to this object (the destination)
      name = otherCustomer.name;
  
      //must make a new scores object to store a copy of the other student 
      if (purchases != nullptr)
          delete[] purchases;
  
      purchases = new int[3];
      for (int i = 0; i &lt; 3; i++) {
          purchases[i] = otherCustomer.purchases[i];
      }
  
      //return this existing object so we can chain this operator 
      return *this;
  }
  
  string Customer::save()
  {
      stringstream out;
      out &lt;&lt; this-&gt;customerID &lt;&lt; &quot;;&quot;;
      out &lt;&lt; this-&gt;title &lt;&lt; &quot;;&quot;;
      out &lt;&lt; this-&gt;name &lt;&lt; &quot;;&quot;;
      out &lt;&lt; this-&gt;numOfPurchases &lt;&lt; &quot;;&quot;;
      int* purchases = 0;
      purchases = purchases | (purchaseArray[0] &lt;&lt; 24);
      purchases = purchases | (purchaseArray[1] &lt;&lt; 16);
      purchases = purchases | (purchaseArray[2] &lt;&lt; 8);
      out &lt;&lt; this-&gt;type &lt;&lt; &quot;;&quot;;
      out.flush();
      return out.str();
  }
  
  void Customer::parse(string line)
  {
      stringstream in(line);
      string customerIDLine;
      getline(in, customerIDLine, ';');
      customerID = stoi(customerIDLine);
      getline(in, title, ';');
      getline(in, name, ';');
  
      int numOfPurchases;
      getline(in, numOfPurchases, ';');
      int s = stoi(numOfPurchases);
  
      purchasesArray[0] = (s &amp; (255 &lt;&lt; 16)) &gt;&gt; 16;
      purchasesArray[1] = (s &amp; (255 &lt;&lt; 8)) &gt;&gt; 8;
      purchasesArray[2] = s &amp; 255;
  
      getline(in, type, ';');
  }  
  
  Customer::~Customer() {
      cout &lt;&lt; &quot;Destructor ~Customer called&quot; &lt;&lt; endl;
      delete[] purchases;
  }
  
  // Overloaded insertion operator  (Outputs Character object data as an output stream)
  // Defined in header file as a  &quot;friend&quot; function, as it is not a member function
  //
  ostream&amp; operator&lt;&lt;(ostream&amp; out, Customer&amp; customer)
  {
      cout &lt;&lt; &quot;Customer details ( output by insertion operator&lt;&lt; )&quot; &lt;&lt; endl;
      cout &lt;&lt; &quot;Customer ID: &quot; &lt;&lt; customer.customerID &lt;&lt; endl;
      cout &lt;&lt; &quot;Title: &quot; &lt;&lt; customer.title &lt;&lt; endl;
      cout &lt;&lt; &quot;Name: &quot; &lt;&lt; customer.name &lt;&lt; endl;
      cout &lt;&lt; &quot;Number of purchases: &quot; &lt;&lt; customer.numOfPurchases &lt;&lt; endl;
      cout &lt;&lt; &quot;Purchases: &quot;;
      for (int i = 0; i &lt; 3; i++)
      {
          if (i &gt; 0) cout &lt;&lt; &quot;,&quot;;
          cout &lt;&lt; customer.purchases[i];
      }
      cout &lt;&lt; &quot;Type: &quot; &lt;&lt; customer.type &lt;&lt; endl;
      
      return out;
  }
  
  
  istream&amp; operator&gt;&gt; (istream&amp; in, Customer&amp; customer)
  {
      cout &lt;&lt; &quot;Enter Customer details ( using the extraction operator&gt;&gt; )&quot; &lt;&lt; endl;
      cout &lt;&lt; &quot;Enter Customer ID: &quot; &lt;&lt; endl;
      cin &gt;&gt; customer.customerID;
      cout &lt;&lt; &quot;Enter Title: &quot; &lt;&lt; endl;
      getline(cin, customer.title);
      cout &lt;&lt; &quot;Enter Name: &quot; &lt;&lt; endl;
      getline(cin, customer.name);
      cout &lt;&lt; &quot;Enter Number of Purchases: &quot;;
      cin &gt;&gt; customer.numOfPurchases; 
      cout &lt;&lt; &quot;Enter Purchases: &quot;;
      cin &gt;&gt; customer.purchases[0];
      cin &gt;&gt; customer.purchases[1];
      cin &gt;&gt; customer.purchases[2];
      cout &lt;&lt; &quot;Enter Type&quot;;
      getline(cin, customer.type);
      cout &lt;&lt; endl;
  
      return in;
  }
  
  int Customer::getCustomerID()
  {
      return customerID;
  }
  
  string Customer::getTitle()
  {
      return title;
  }
  
  string Customer::getName()
  {
      return name;
  }
  
  int Customer::getNumOfPurchases()
  {
      return numOfPurchases;
  }
  
  int* Customer::getPurchases()
  {
      return purchases;
  }
  
  string Customer::getType()
  {
      return type;
  }
  
  void Customer::setCustomerID(int customerID)
  {
      if (customerID &lt; 1) {
          cout &lt;&lt; &quot;Customer ID has to be equal to 1 or more&quot; &lt;&lt; endl; //Changed all the &quot;throw invalid_argument&quot; messages to cout as they were causing an issue with my main.cpp file and an abort message kept appearing every time I ran my main.cpp file.
      }
      this-&gt;customerID = customerID;
  }
  
  void Customer::setTitle(string title)
  {
      if (title.length() &lt; 2) {
          cout &lt;&lt; &quot;Title has to be more than or equal to 2 characters&quot; &lt;&lt; endl;
      }
      this-&gt;title = title;
  }
  
  void Customer::setName(string name)
  {
      if (name.length() &lt; 4) {
          cout &lt;&lt; &quot;Length of name should be more than or equal to 4 characters&quot; &lt;&lt; endl;
      }
      this-&gt;name = name;
  }
  
  //Got help ith this on stack overflow as I was using &quot;&amp;&amp;&quot; instead of using &quot;||&quot; for the if statement
  void Customer::setNumOfPurchases(int numOfPurchases)
  {
      if(numOfPurchases &lt;0 || numOfPurchases &gt; 10000){
          cout &lt;&lt; &quot;Number of purchases should be between 0 to 10000&quot; &lt;&lt; endl;
      }
      this-&gt;numOfPurchases = numOfPurchases;
  }
  
  void Customer::setPurchases(int purchase1, int purchase2, int purchase3)
  {
      if (purchase1 &lt; 0 || purchase2 &lt; 0 || purchase3 &lt; 0) {
          cout &lt;&lt; &quot;Purchases must be more than or equal to zero&quot; &lt;&lt; endl;
      }
  }
  
  //Got help from stack overflow on comparing strings as I originally didnt use &quot;type.compare&quot;
  void Customer::setType(string type) {
      if (type.compare(&quot;New&quot;) !=0 || type.compare(&quot;Either&quot;) !=0) {
          cout &lt;&lt; &quot;Type of purchase has to be New or Either&quot; &lt;&lt; endl;
      }
  }
  </code></pre>
  <p>Code in the <code>Customer.h</code> file:</p>
  <pre><code>#pragma once
  #include&lt;iostream&gt;
  using namespace std;
  #include&lt;string&gt;
  
  class Customer
  {
  private:
      int customerID;
      string title;
      string name;
      int numOfPurchases;
      int* purchases;
      string type;
  
  public:
      Customer(); // default constructor
      Customer(int customerID, string title, string name, int numOfPurchases, int purchase1, int purchase2, int purchase3, string type);
      
      //copy overload assignment
      Customer&amp; operator=(Customer&amp; otherCustomer);
      Customer(const Customer&amp; source);
  
      string save();
      void parse(string line);
      ~Customer(); //destructor
  
  
      //Getters and Setters
      void setCustomerID(int customerID);
      void setTitle(string title);
      void setName(string name);
      void setNumOfPurchases(int numOfPurchases);
      void setPurchases(int purchase1, int purchase2, int purchase3);
      void setType(string type);
  
      int getCustomerID();
      string getTitle();
      string getName();
      int getNumOfPurchases();
      int* getPurchases();
      string getType();
  
      void printCustomer() {
          cout &lt;&lt; customerID &lt;&lt; &quot;,&quot; &lt;&lt; title &lt;&lt; &quot;,&quot; &lt;&lt; name &lt;&lt; &quot;,&quot; &lt;&lt; numOfPurchases &lt;&lt; &quot;,&quot; &lt;&lt; purchases &lt;&lt; &quot;,&quot; &lt;&lt; type &lt;&lt; endl;
      }
  
      
  
      friend std::ostream&amp; operator&lt;&lt;(std::ostream&amp; out, Customer&amp; customer); // overloaded operator&lt;&lt;
      friend istream&amp; operator&gt;&gt; (istream&amp; in, Customer&amp; customer); // overloaded operator &gt;&gt;
  };
  </code></pre>
  <p>Code from the <code>Main.cpp</code> file:</p>
  <pre><code>// Repeat_Assessment_C++_AislingSmith.cpp : This file contains the 'main' function. Program execution begins and ends there.
  //
  
  #include &lt;iostream&gt;
  #include &lt;fstream&gt;
  #include &lt;string&gt;
  #include &lt;sstream&gt;
  #include &lt;vector&gt;
  #include &quot;Customer.h&quot;
  using namespace std;
  
  
  void OutputFileStream();
  void parseLine(const string&amp; str);
  void InputFileStream();
  void save(vector&lt;Customer&gt; customers);
  void load(vector&lt;Customer&gt;&amp; customers);
  void addCustomer(vector&lt;Customer&gt;&amp; vect);
  //void printActions();
  
  
  void OutputFileStream()
  {
      cout &lt;&lt; &quot;Creating and writing to file: Customer.txt&quot; &lt;&lt; endl;
  
      ofstream outStream(&quot;customers.txt&quot;);  // write mode (overwrites existing data)
  
      if (outStream.good())
      {
          int customerID = 150033;
          outStream &lt;&lt; &quot;This is a line of text.\n&quot;;
          outStream &lt;&lt; &quot;This is another line of text.\n&quot;;
          outStream &lt;&lt; &quot;This is a line of text.\n&quot;;
          int numOfPurchases = 4;
          int purchases = 0;
          outStream &lt;&lt; customerID &lt;&lt; &quot;Mr&quot; &lt;&lt; &quot;Jack&quot; &lt;&lt; &quot;New&quot; &lt;&lt; numOfPurchases &lt;&lt; purchases &lt;&lt; endl;
  
          outStream.close(); //  close file
          cout &lt;&lt; &quot;File written.\n&quot; &lt;&lt; endl;
      }
      else
          cout &lt;&lt; &quot;Unable to open file&quot;;
  }
  
  void parseLine(const string&amp; str) {
  
      stringstream strStream(str); //create string stream from the string
     // int customerID;
      string title;
      string name;
      string type;
      //int numOfPurchases;
      //int purchases;
      string s;
     
      int customerID = 150033;
      getline(strStream, s, ';');
      customerID = stoi(s);
  
      getline(strStream, title, ';');
      getline(strStream, name, ';');
      getline(strStream, type, ';');
  
      int numOfPurchases = 4;
      getline(strStream, s, ';');
      numOfPurchases = stoi(s);
  
      int purchases = 0;
      getline(strStream, s, ';');
      purchases = stoi(s);
      int* purchasesArray = new int[3];
      purchasesArray[0] = (purchases &amp; (255 &lt;&lt; 16)) &gt;&gt; 16;
      purchasesArray[1] = (purchases &amp; (255 &lt;&lt; 8)) &gt;&gt; 8;
      purchasesArray[2] = purchases &amp; 255;
      for (int i = 0; i &lt; 3; i++)
      {
          int purchasesArray[3];
      }
  
      cout &lt;&lt; &quot; CustomerID: &quot; &lt;&lt; customerID &lt;&lt; &quot;Title:&quot; &lt;&lt; title &lt;&lt; &quot; Name: &quot; &lt;&lt; name &lt;&lt; &quot; Type:&quot; &lt;&lt; type &lt;&lt; &quot; Number of Purchases: &quot; &lt;&lt; numOfPurchases &lt;&lt; &quot;Purchases: &quot; &lt;&lt; purchases &lt;&lt; endl;
  }
  
  void InputFileStream() {
      cout &lt;&lt; &quot;Reading from a semi-colon delimited txt file&quot; &lt;&lt; endl;
  
      string line;
      ifstream inStream(&quot;customers.txt&quot;); //opens file as an input file stream
      if (inStream.good()) //if the file is opened successfully and not empty
      {
          while (getline(inStream, line)) //reads line until false return
          {
              parseLine(line);
          }
          inStream.close();
      }
      else
          cout &lt;&lt; &quot;unable to open file or the file is empty!&quot;;
  }
  
  void save(vector&lt;Customer&gt; customers)
  {
      ofstream out(&quot;customers.txt&quot;);
      if(out)
      {
          for (Customer&amp; c : customers)
          {
              out &lt;&lt; c.save();
          }
          out.flush();
          out.close();
      }
      else
      {
          cout &lt;&lt; &quot;Error Writing to File&quot; &lt;&lt; endl;
      }
  }
  
  void load(vector&lt;Customer&gt;&amp; customers)
  {
      ifstream in(&quot;customers.txt&quot;);
      if (in) {
          string line;
          while (!in.eof())
          {
              getline(in, line);
              if (line != &quot;&quot;)
              {
                  Customer c;
                  c.parse(line);
                  customers.push_back(c);
              }
          }
      }
  }
  
  void addCustomer(vector&lt;Customer&gt;&amp; customers) {
      Customer customer;
      cin &gt;&gt; customer;
      customers.push_back(customer);
      
  }
  
  
  
  int main()
  {
      InputFileStream();
      vector&lt;Customer&gt; customers;
      Customer c;
  
      Customer cust1;
  
      cust1.setCustomerID(150032);
      cust1.setTitle(&quot;Mr&quot;);
      cust1.setName(&quot;Joey&quot;);
      cust1.setNumOfPurchases(3);
      cust1.setPurchases(366, 352, 334);
      cust1.setType(&quot;New&quot;);
  
      cout &lt;&lt; cust1.getCustomerID() &lt;&lt; endl;
      cout &lt;&lt; cust1.getTitle() &lt;&lt; endl;
      cout &lt;&lt; cust1.getName() &lt;&lt; endl;
      cout &lt;&lt; cust1.getNumOfPurchases() &lt;&lt; endl;
      cout &lt;&lt; cust1.getPurchases() &lt;&lt; endl;
      cout &lt;&lt;  cust1.getType() &lt;&lt; endl;
     
      
  
  
      return 0;
     
  
  }
  </code></pre>