title: Reading txt file using ifstream in C++ Builder 6
body: <p>I'm using C++ BUILDER 6 and I'm trying to understand this code.</p>
  
  <p>I'm logging 4 variables into a txt file and obtaining success:</p>
  
  <pre><code>sprintf(buffer, "%i,%i,%i,%i", x, yMin, yMed, yMax);
  ofstream logData;
  logData.open("logData.txt", ios::app);
  logData &lt;&lt; buffer &lt;&lt; "\n";
  </code></pre>
  
  <p>My txt output:</p>
  
  <pre><code>1,1686,1784,1972
  2,1687,1785,1973
  3,1688,1786,1974
  ...
  </code></pre>
  
  <p>I need to read this file to get variables back and plot to a graph. I'm doing like this and it's working properly:</p>
  
  <pre><code>std::ifstream infile(OpenDialog-&gt;FileName.c_str());
  int num, y, yMin, yMax;
  char a,b,c;
  char buffer[100];
  if(infile.is_open())
  {
      while (infile &gt;&gt; x &gt;&gt; a &gt;&gt; yMin &gt;&gt; b &gt;&gt; yMed &gt;&gt; c &gt;&gt; yMax)
      {
          sprintf(buffer, "X: %i | YMIN: %i | YMED: %i | YMAX: %i", x, yMin, yMed, YMax);
          Memo1-&gt;Lines-&gt;Add(buffer);
      }
  }
  </code></pre>
  
  <p>My Memo1 output:</p>
  
  <pre><code>X:1 | YMIN: 1686 | YMED: 1784 | YMAX: 1972
  X:2 | YMIN: 1687 | YMED: 1785 | YMAX: 1973
  X:3 | YMIN: 1688 | YMED: 1786 | YMAX: 1974
  ...
  </code></pre>
  
  <p><strong>My question is:</strong> How did C++ distinguish the variables? I didn't get where it assumes that <code>x = 1</code>, <code>yMin = 1686</code> ... by the while loop reading line by line of txt file:</p>
  
  <pre><code>while (infile &gt;&gt; x &gt;&gt; a &gt;&gt; yMin &gt;&gt; b &gt;&gt; yMed &gt;&gt; c &gt;&gt; yMax)
  </code></pre>
  
  <p>When the code enters to sprinft line:</p>
  
  <p><code>sprintf(buffer, "X: %i | YMIN: %i | YMED: %i | YMAX: %i", x, yMin, yMed, YMax);</code></p>
  
  <p>The variables x, yMin, yMed, YMax already assumed some value from txt file.</p>
  
  <p>Note: In my understood C++ expects some INT + CHAR + INT + CHAR... Where the CHAR is a ','. But '1' is a CHAR too and if I log:</p>
  
  <pre><code>1116861178411972 instead 1,1686,1784,1972
  </code></pre>
  
  <p>It doesn't works properly.</p>
  
  <p>Can someone give me some guide? Somewhere to start to understand it?</p>