title: cout outputting jibberish line of message instead of actual user's cout statement
body: <p>This is my header file</p>
  
  <pre><code>#ifndef KINGDOM_H_
  #define KINGDOM_H_
  
  #include &lt;string&gt;
  using namespace std;
  namespace sict{
      class Kingdom {
      public:
          char m_name[32];
          int m_population;
  
      };
      void display(Kingdom&amp; pKingdom);
  }
  #endif
  </code></pre>
  
  <p>and these are my cpp files</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;string&gt;
  #include "kingdom.h"
  
  using namespace std;
  
  namespace sict {
  
      void display(Kingdom&amp; pKingdom) {
          cout &lt;&lt; pKingdom.m_name &lt;&lt; ", population " &lt;&lt; pKingdom.m_population &lt;&lt; endl;
      }
  }
  </code></pre>
  
  <p>And this is my last cpp file</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include "Kingdom.h"
  
  using namespace std;
  using namespace sict;
  
  void read(sict::Kingdom&amp;);
  
  int main() {
      int count = 0; // the number of kingdoms in the array
      Kingdom* pKingdom = nullptr;
  
  
      cout &lt;&lt; "==========\n"
          &lt;&lt; "Input data\n"
          &lt;&lt; "==========\n"
          &lt;&lt; "Enter the number of Kingdoms: ";
      cin &gt;&gt; count;
      cin.ignore();
  
      if (count &lt; 1) return 1;
  
  
      pKingdom = new Kingdom[count];
      for (int i = 0; i &lt; count; ++i) {
          cout &lt;&lt; "Kingdom #" &lt;&lt; i + 1 &lt;&lt; ": " &lt;&lt; endl;
          cin &gt;&gt; i;
          cout &lt;&lt; "Enter the name of the Kingdom: " &lt;&lt; pKingdom[i].m_name;
          cin &gt;&gt; pKingdom[i].m_name;
          cout &lt;&lt; "Enter the number people living in " &lt;&lt; pKingdom[i].m_population &lt;&lt; ": ";
          cin &gt;&gt; pKingdom[i].m_population;
  
      }
      cout &lt;&lt; "==========" &lt;&lt; endl &lt;&lt; endl;
  
      // testing that "display(...)" works
      cout &lt;&lt; "------------------------------" &lt;&lt; endl
          &lt;&lt; "The 1st kingdom entered is" &lt;&lt; endl
          &lt;&lt; "------------------------------" &lt;&lt; endl;
      sict::display(pKingdom[0]);
      cout &lt;&lt; "------------------------------" &lt;&lt; endl &lt;&lt; endl;
  
  
      delete[]pKingdom;
      pKingdom = nullptr;
              return 0;
  }
  
  // read accepts data for a Kingdom from standard input
  
  void read(sict::Kingdom&amp; kingdom) {
  
      cout &lt;&lt; "Enter the name of the Kingdom: ";
      cin.get(kingdom.m_name, 32, '\n');
      cin.ignore(2000, '\n');
      cout &lt;&lt; "Enter the number of people living in " &lt;&lt; kingdom.m_name &lt;&lt; ": ";
      cin &gt;&gt; kingdom.m_population;
      cin.ignore(2000, '\n');
  }
  </code></pre>
  
  <p>When the code gets to the part Enter the Kingdom name, it would prompt the user for answer, but before it prompts, it just outputs jibberish like this</p>
  
  <p><a href="https://i.imgur.com/MSSHgvz.png" rel="nofollow noreferrer">https://i.imgur.com/MSSHgvz.png</a></p>
  
  <p>Also, when it gets to enter the number of people living in, it would also output "-842150451" before I can even type a valid number.</p>
  
  <p>Any guesses to solve the problem?</p>