title: C++ Read file line by line then split each line using the delimiter
body: <p>i have searched and got a good grasp of the solution from a previous post but I am still stuck a bit.</p>
  
  <p>My problem is instead of "randomstring TAB number TAB number NL"</p>
  
  <p>My data is "number (space colon space) number (space colon space) sentence"</p>
  
  <p>I've edited the code below but still can't get it to work 100% because the parameters getline takes is (stream, string, delimiter).</p>
  
  <p>For some reason, it only gets the first word of the sentence as well and not the rest.</p>
  
  <p>Previous post</p>
  
  <hr>
  
  <p>I want to read a txt file line by line and after reading each line, I want to split the line according to the tab "\t" and add each part to an element in a struct.</p>
  
  <p>my struct is 1*char and 2*int</p>
  
  <pre><code>struct myStruct
  {
      char chr;
      int v1;
      int v2;
  }
  </code></pre>
  
  <p>where chr can contain more than one character.</p>
  
  <p>A line should be something like:</p>
  
  <p>randomstring TAB number TAB number NL</p>
  
  <p>SOLUTION</p>
  
  <pre><code>std::ifstream file("plop");
  std::string   line;
  
  while(std::getline(file, line))
  {
      std::stringstream   linestream(line);
      std::string         data;
      int                 val1;
      int                 val2;
  
      // If you have truly tab delimited data use getline() with third parameter.
      // If your data is just white space separated data
      // then the operator &gt;&gt; will do (it reads a space separated word into a string).
      std::getline(linestream, data, '\t');  // read up-to the first tab (discard tab).
  
      // Read the integers using the operator &gt;&gt;
      linestream &gt;&gt; val1 &gt;&gt; val2;
  }
  </code></pre>
  
  <hr>