title: reading buffer C++
body: <p>I'm trying to read buffer in C++ one character at the time until '\n', and initialize char array with these characters using do-while loop. I know I could use cin.getline(), but I want to try it on my own. </p>
  
  <pre><code>int main()
  {
      char buffer [1024];
      int index = 0;
      char temp;
  
      do 
      {
          cin.get( temp );
          buffer [ index ] = temp;
          index ++;
      }
      while ( temp != '\n' );
  
      cout &lt;&lt; buffer &lt;&lt; endl;
  
      return 0;
  } 
  </code></pre>
  
  <p>It gives me incorrect result-the proper text fallow by couple of lines of squre brackets mixed with other weird symbols.</p>