title: Odd Cout Behavior
body: <p>I'm sorry for the initial post. This is tested and reproducible.</p>
  
  <p>I'm trying to get <strong>cout</strong> to work within a fstream while loop while detecting each character its parsing, but it's exhibiting an odd behavior with the Text getting overrided by the first variable that I'm trying to put into cout.</p>
  
  <p><strong>main.cxx</strong></p>
  
  <pre><code>#include &lt;string.h&gt;
  #include &lt;fstream&gt;
  #include &lt;iostream&gt;
  #include &lt;stdio.h&gt;
  
  using std::string;
  using std::fstream;
  using std::noskipws;
  using std::cout;
  
  int main(int argc, const char *argv[]){
  
      char pipe;
      string word; // stores the word of characters it's working on at the moment
      string filename = "Directory.dat";
      int type = 0; // 2 types counter, starts at 0
      int newindicator = 0; // for detecting a new * for the data set
      fstream fin(filename.c_str(), fstream::in);
      while(fin &gt;&gt; noskipws &gt;&gt; pipe){
          if(pipe == '*'){ // if the character is an asterisk
              type++;
              newindicator = 0;
              word.clear();
          }else if (pipe == '\n'){ // if the character is next line
              if(newindicator == 0){ // tells the reader to know that it just finished reading a *, so it doesn't print anything.
                  newindicator = 1;
              }else {
                  if(type == 1){ 
                      cout &lt;&lt; "new word as: ";
                      cout &lt;&lt; word &lt;&lt; "\n";
  
                  }else if (type == 2){ 
                      cout &lt;&lt; "new word as: ";
                      cout &lt;&lt; word &lt;&lt; "\n";
                  }
                  word.clear(); // clears the word string as it's reading the next line.
              }
          }else{
              word+=pipe;
          }
      }
      return 0;
  }
  </code></pre>
  
  <p><strong>Directory.dat</strong></p>
  
  <pre><code>*
  Chan
  Johnathan
  Joespeh
  *
  Betty
  Lady Gaga
  </code></pre>
  
  <p><strong>Output</strong></p>
  
  <pre><code>Chanword as:
  new word as: Johnathan
  new word as: Joespeh
  Bettyord as:
  new word as: Lady Gaga
  </code></pre>
  
  <p>Note that how "Chan" is overriding the characters "new " on the first line, but it's fine after that. This seems to happen on every new type I'm doing, and when its recalling a new set of type. Same with Betty on the next set, which overrides "new w" with "Betty" on that cout.</p>
  
  <p>Any feedback would be much appreciated. Thank you!</p>