title: C++ how to use fstream to read tab-delimited file with spaces
body: <p>I need to use some C++ code to read a tab-delimited text file. The file contains three columns and the second column contains strings with spaces. Below are some examples of the file.</p>
  
  <pre><code>1   hellow world    uid_1
  2   good morning    uid_2
  </code></pre>
  
  <p>The following is the C++ that I need to use to read the file. However, it can't read the file properly when hitting the space in the string.</p>
  
  <p>Any suggestion on modifying the while loop to make it work?  I'm not familiar with C++. Please provide detailed code. Thanks!</p>
  
  <pre><code>#include &lt;Rcpp.h&gt;
  #include &lt;iostream&gt;
  #include &lt;fstream&gt;
  #include &lt;string&gt;
  
  std::ifstream infile (file_name.c_str());
  
  int row = -1; 
  std::string col;
  std::string uid;
  
  
  while (infile &gt;&gt; row &gt;&gt; col &gt;&gt; uid) {
  
      ### operations on row, col and uid ####
  
  }
  </code></pre>