title: string input not printed correctly on the screen
body: <p>I am trying to read in a string from the user input and then print it on screen. However, when the string is printed on the console, it is kind of gibberish. The funny thing is that it works in Visual Studio and not in CodeBlocks.</p>
  <pre><code>#include &lt;iostream&gt;
  #include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;windows.h&gt;
  
  int main() {
      int i, num_bytes;
      char sentence[] = &quot;&quot;;
      std::cout &lt;&lt; &quot;Please enter your name: &quot;;
      //fgets(sentence, 100, stdin);
      //scanf(&quot;%[^\n]%*c&quot;, sentence);
      //scanf(&quot;%[^\n]&quot;, sentence);
      std::cin &gt;&gt; sentence;
      num_bytes = strlen(sentence);
  
      LPVOID ptr = VirtualAlloc(NULL, num_bytes, MEM_RESERVE, PAGE_READWRITE);
      ptr = VirtualAlloc(ptr, num_bytes, MEM_COMMIT, PAGE_READWRITE);
  
      if (ptr) {
          char* char_ptr = static_cast&lt;char*&gt;(ptr);
  
          for (i = 0; i &lt; num_bytes; i++) {
              char_ptr[i] = sentence[i];
          }
  
          std::cout &lt;&lt; &quot;Allocated Memory Address: &quot; &lt;&lt; (void *)ptr &lt;&lt; std::endl;
  
          std::cout &lt;&lt; &quot;Press Enter to print out the characters.\n&quot;;
          getchar();
  
          for (i = 0; i &lt; num_bytes; i++) {
              std::cout &lt;&lt; char_ptr[i];
          }
  
          std::cout &lt;&lt; &quot;\nPress Enter to clear memory.&quot; &lt;&lt; std::endl;
          getchar();
  
          VirtualFree(ptr, 0, MEM_RELEASE);
      } else {
          std::cout &lt;&lt; &quot;Could not allocate &quot; &lt;&lt; num_bytes &lt;&lt; &quot; of memory.&quot; &lt;&lt; std::endl;
      }
  
      std::cout &lt;&lt; &quot;\nPress Enter to continue.&quot; &lt;&lt; std::endl;
      getchar();
  }
  </code></pre>