 <p>Take a look at this example: <a href="http://ideone.com/8MHGH" rel="nofollow">http://ideone.com/8MHGH</a></p> <p>The main problem you have is that str is pointer to a char not a char, so you should assign it to a string: <code>str = "\0";</code></p> <p>When you assign it to char, it remains 0 and then the fail bit of cout becomes true and you can no longer print to it. Here is another example where this is fixed: <a href="http://ideone.com/c4LPh" rel="nofollow">http://ideone.com/c4LPh</a></p>