title: C++ Read a delimited file and create an object
body: <p>I am trying to read a file use the data line by line to create into an object.</p>
  
  <p>The current file I have is like this and the code reading the file will be found below.</p>
  
  <pre><code>*   1223 Fake1 Name1  60  70  80  24 89  add1  Male
      1224 Fake2 Name2  61  70  81  80 24  add2  Male
      1225 Fake3 Name3  63  70  82  80 89  add3  Male
      1226 Fake4 Name4  63  70  83  80 88  add4  Male*
  </code></pre>
  
  <p>The problem I am having is that I need to put delimiters in the file so that a person can have more than one name and also the address can now hold multiple strings until the delimiter.</p>
  
  <p>I would like to change my file to this;</p>
  
  <pre><code>   *1223 : Fa1 Name1 : 60 : 70 : 80 : 24 :89 : This will be address1 : Male 
      1224 : Fake2 Name2 : 61 : 70 : 81 : 80 :24 : This will be address2 : Male
      1225 : Fake3 Name3 : 63 : 70 : 82 : 80 :89 : This will be address3 : Male
      1226 : Fake4 Name4 : 63 : 70 : 83 : 80 :88 : This will be address4 : Male*
  </code></pre>
  
  <p>How can I update the code below so that it can use the delimiters to create an object?</p>
  
  <pre><code>void loadFile(Person people[], int* i)
  {
      ifstream infile("people2.txt");
  
      if ( !infile.is_open()) {
        // The file could not be opened
          cout &lt;&lt; "Error";
      }
      else
      {
          string str, str1, str2, str3, str4;
          int x[6];
          while(!infile.eof())
          {
              infile &gt;&gt; str1; 
  
              infile &gt;&gt; str2; 
  
              inile &gt;&gt; str; 
              x[0] = stoi(str);
  
              infile &gt;&gt; str; 
              x[1] = stoi(str);
  
              infile &gt;&gt; str; 
              x[2] = stoi(str);
  
              infile &gt;&gt; str; 
              x[3] = stoi(str);
  
              infile &gt;&gt; str; 
              x[4] = stoi(str);
  
              infile &gt;&gt; str; 
              x[5] = stoi(str);
              infile &gt;&gt; str3; 
              infile &gt;&gt; str4;             
              people[*i] = Person( x[0], str2 + " " + str1, x[1], x[2], x[3], x[4], x[5], str3, str4);
              (*i)++;
          }
          infile.close();
      }
  
  }
  </code></pre>