Extraordinary display bug
<p>Good evening. Sorry for the title I can't be more precise about the problem.</p>

<p><strong>The following code display nothing to screen unless :</strong></p>

<p><strong>1. I put off the three unused commented lines at the beginning and which make no conflict of any kind.</strong></p>

<p><strong>2. Unless I change the "Hello" by "Hello world" in main( ).</strong></p>

<p>I'm using codeblocks 10.05.</p>

<p><strong>Full code :</strong></p>

<pre><code>#include &lt;iostream&gt;
using namespace std;

class stringclass
{
   protected :

      inline bool success()   { failbit = false;  return true; } //line to ignore
      inline bool fail()      { failbit = true; return false; } //line to ignore

   public :

      bool failbit; //line to ignore

      char * mystring;
      long memsize;
      long length;

      void reset();
      void alloc(long newsize);

      void copy(const stringclass &amp; other);

      stringclass(const char str[]);
      stringclass()                          {reset(); }
      stringclass(const stringclass &amp; other) {copy(other); }
      ~stringclass()                         {delete [] mystring;}

      friend ostream&amp; operator &lt;&lt; (ostream&amp; out, stringclass &amp; obj)   {out &lt;&lt; obj.mystring; return out;}

};

void stringclass::reset()
{
   delete [] mystring;
   mystring = NULL;
   length = 0;
   memsize = 0;
}

void stringclass::alloc(long newsize)
{
   delete [] mystring;

   mystring = new char[newsize];

   memsize = newsize;
   mystring[0] = 0;
   length = 0;
}

void stringclass::copy(const stringclass &amp; other)
{
   if(other.mystring == NULL) reset();
   else
   {
      alloc(other.memsize);
      strcpy(mystring, other.mystring);
      length = strlen(mystring);
   }
}

stringclass::stringclass(const char str[])
   : mystring(NULL), memsize(0), length(0)
{
   if(str == NULL) reset();
   else
   {
      alloc(strlen(str) + 1);
      strcpy(mystring, str);
      length = strlen(mystring);
   }
}

int main()
{
      stringclass str = "Hello";
      stringclass str2 = str;

      cout &lt;&lt; "str = " &lt;&lt; str &lt;&lt; endl;
      cout &lt;&lt; "str2 = " &lt;&lt; str2 &lt;&lt; endl;
      cout &lt;&lt; endl;

      system("PAUSE");
      return 0;
}
</code></pre>

<p><strong>The code displays :</strong></p>

<pre><code>str =
str2 =

Press any key to continue...
</code></pre>

<p><strong>after the code change 1. :</strong></p>

<pre><code>str = Hello
str2 = Hello

Press any key to continue...
</code></pre>

<p><strong>after the code change 2. :</strong></p>

<pre><code>str = Hello world
str2 = Hello world

Press any key to continue...
</code></pre>
