title: Clearing the cout buffer (c++)
body: <p>Hello I'm writing a short program to implement a shell and I'm running into an unusual problem. For some reason I can't clear to the std::cout buffer. The program wont print out messages. I understand a simple solution is to switch to std::cerr, but is there a way to get messages to print with cout? 
  Things I've tryed:</p>
  
  <ol>
  <li><code>std::cout.flush()</code> </li>
  <li>Inserting <code>std::endl</code> after anything is written to standard out. </li>
  <li>Inserting an <code>std::flush</code> into the output stream </li>
  <li><code>std::cout.setf(std::ios::unitbuf);</code> which was something I found that      should unbuffer output.</li>
  </ol>
  
  <p>Any help is much appreciated here is my code:</p>
  
  <pre><code>int main()
  {
      //Tryed this to unbuffer cout, no luck.
      std::cout.setf(std::ios::unitbuf);
  
      std::string input;
  
      //Print out shell prompt and read in input from keyboard.
      std::cout &lt;&lt; "myshell&gt; ";   
      std::getline(std::cin, input);
  
      //**********************************************************************
      //Step 1) Read in string and parse into tokens.
      //**********************************************************************
  
      char * buf = new char[input.length() + 1];
      strcpy(buf, input.c_str());
  
      int index = 0;
      char * command[256]; 
  
      command[index] = std::strtok(buf, " ");    //Get first token.
      std::cout &lt;&lt; command[index] &lt;&lt; std::endl;
  
      while (command[index] != NULL)
      {
          ++index;
          command[index] = std::strtok(NULL," ");    //Get remaining tokens.
          std::cout &lt;&lt; command[index] &lt;&lt; std::endl;
      }   
  
      std::cout.flush(); //No luck here either
  
      //HERE IS WHERE MY PROBLEM IS.
      std::cout &lt;&lt; index &lt;&lt; " items were added to the command array" &lt;&lt; std::endl;
  
      delete[] buf;
  
      return 0;   
  }
  </code></pre>