title: C++ file reading and split columns
body: <p>I'm not familiar with C++ file reading, but I've done a lot via pyspark. 
  So right now I have a txt file that reads as follows:</p>
  
  <pre><code>1   52  Hayden Smith        18:16   15  M   Berlin
  
  2   54  Mark Puleo      18:25   15  M   Berlin
  
  3   97  Peter Warrington    18:26   29  M   New haven
  
  4   305 Matt Kasprzak       18:53   33  M   Falls Church
  
  5   272 Kevin Solar     19:17   16  M   Sterling
  
  6   394 Daniel Sullivan     19:35   26  M   Sterling
  
  7   42  Kevan DuPont        19:58   18  M   Boylston
  
  8   306 Chris Goethert      20:00   43  M   Falls Church
  </code></pre>
  
  <p>As you can see there are 8 columns and 351 rows(which I've only shown 8 rows),
  for each row, [0] is ranking, [1] is BIB, [2] is firstname, [3] is lastname, [4] is time, [5] is age, [6] is sex, [7] is town
  for example, the first row, 1 is ranking, 52 is BIB, Hayden Smith is name, 18:16 is time, 15 is age, M is male, Berlin is town.</p>
  
  <p>I have a sorted linked structure, called: Class SortedLinked
  and an itemtype class, called: Class Runner</p>
  
  <p>you don't need to worry about the SortedLinked class.</p>
  
  <p>Class Runner has four private attributes:</p>
  
  <pre><code>string name, int age, int min, int sec
  </code></pre>
  
  <p>In my driver file, I can do this:</p>
  
  <pre><code>SortedLinked mylist                  // initialize a sorted list
  
  Runner M("Jordan", 22, 20, 20)       // initialize a Runner called Jordan, who is 22 years old, and finished the race in 20 mins and 20 sec
  
  mylist.add(M) //add Runner M into my sorted list
  </code></pre>
  
  <p>So I need to read the text file and and create a Runner object with the runner's name, age, number of minutes, and number of seconds. Insert that Runner into a sorted linked list.</p>
  
  <p>So if this is in pyspark, I can just do this:</p>
  
  <pre><code>file=sc.textFile("hdfs")             //we usually use hdfs in pyspark
  
  newfile = file.map(lambda line: line.split('\t')    //for each column, they are seperated by Tabs, except column[2][3] are separated by a space 
  
  ColumnIneed = newfile.filter(lambda r: [r[2], r[3], r[4], r[5]]) // I only need the column [2][3][4][5]
  
  mylist = ColumnIneed.collect()    // transform the RDD into a list
  
  Then I can just transform every row into a Runner object.
  </code></pre>
  
  <p>BUT, in C++ I only know this:</p>
  
  <pre><code>ifstream, infile;
  
  string s, sAll;
  
  if(infile.is_open())
  {
  
     while(getline(line, s))
  
     {
  
        s = s.rstrip('\n')     //does NOT work in C++
        name, age, time = s.split('\t')  // Does NOT work in C++ and I dont need all the columns
  </code></pre>
  
  <p>SO, problem:</p>
  
  <p>1, I need to access each line, and strip the newline </p>
  
  <p>2, I only need the column [2][3][4][5] // each column is separated by Tabs</p>
  
  <p>3, column[4] is time, which is string in the textfile, I need to split ":" and put into mintues and seconds</p>
  
  <p>4, column[2][3] are first and last names, I need to combine them into string name</p>
  
  <p>5, column[2][3] are separated by spaces </p>
  
  <p>so ideally, I want to do this:</p>
  
  <pre><code>while(I need a loop)
  {
  
     eachline = access each line;
  
     eachline.strip('\n')  //strip newline
  
     eachline.split('\t')  //split Tabs
  
     string name = eachline[2][3];
  
     string time = eachline[4];
  
     int min;
  
     int sec;
  
     min, sec = time.split(':")
  
     int age = eachline[5];
  
     Runner M(name, age, min, sec)    //I don't know if this works, because it looks like you are overwriting the Runner M each time you access a new line. 
  
     mylist.add(M)      //add M into my linkedlist, this step you don't need to worry, I already finished. 
  
  }
  </code></pre>
  
  <p>if you have a better way of doing, I would really appreciate it. </p>