Menu

Debug problems

2003-02-19
2012-09-26
  • Artyom Grigoryev

    Recently downloaded dev-cpp v. 4.9.7.0
    Here is the code that I'm trying to 'debug'

    #include <iostream>
    #include <stdlib.h>
    class World
    {
    public:
        World ()  { std::cout << "Hello!\n"; }
        ~World () { std::cout << "Good bye!\n"; }
    };

    World TheWorld;

    int main()
    {
      int x;
      x = 3;
      std::cout << x;
      system("PAUSE");   
      return 0;
    }

    As you can see there are three outputs.  None of them work in the debug mode (the screen stays blank).  Any ideas?

    Btw debug doesn't work unless you put "-g" in the debug options.

     
    • Larry Young

      Larry Young - 2003-02-20

      Here are two possibilities for you to explore:
      1 - Your "TheWorld" object is global; there is no guarantee that std::cout is constructed before TheWorld.  Test this by putting the instantiation of this object inside "main()".
      2 - std::cout is not automatically flushed, so the output may be stuck in a buffer when system("pause") is called.  Try flushing cout by adding "<< endl" to your code, e.g.,
      std::cout << "Hello!" << std::endl;
      std::cout << x << std::endl;

       
    • EzNet

      EzNet - 2007-01-10

      Thank you for the "-g" tid-bit!

      I have been going nuts trying to get debug to work!

      Thank you again.

       

Log in to post a comment.