The forums have permanently moved to forum.kirupa.com. This forum will be kept around in read-only mode for archival purposes. To learn how to continue using your existing account on the new forums, check out this thread.


Results 1 to 8 of 8

Thread: What's With The Error Message?

  1. #1

    What's With The Error Message?

    I ran my console program and everything compiled correctly and everything is exactly how I want it to be. But after about three or four seconds of running the program, I get an error message saying that my program (Project.exe) has encountered an error and has to close. Does anyone have any idea why this is happening and what I can do to stop it? Thanks in advance.
    Slinky + Escalator = Everlasting Fun!

  2. #2
    1,627
    posts
    hugeExplosions = true;
    It's crashed?

    You probably have programmed something incorrectly (computers aren't often wrong on their own!) and it's causing your program to throw an unhandled exception. Are you running Visual C++ or an IDE which can catch unhandled exceptions during runtime, or did you compile from command line and are just running the program standalone?
    MS Paint FTW!


  3. #3
    Sounds rather like a classic case of accessing unallocated memory. Check if you run out of array boundaries somewhere or use an uninitialized pointer.

  4. #4
    Hm, well I'm not using any arrays or pointers (at least I don't think so) since I'm fairly new to C++ and only use basic code as of now. Here's the code I'm using. I don't think anything is set wrong because the output in the console is what I wanted it to be. Let me know if you find any bugs in it.

    header.h
    using namespace std;
    extern int variable;
    void function();
    main.cpp
    #include <cstdlib>
    #include <iostream>
    #include "header.h"
    using namespace std;
    int main(int argc, char *argv[])
    {
    variable = 20;
    function();
    system("PAUSE");
    return 0;
    }
    proto.cpp
    #include <cstdlib>
    #include <iostream>
    #include "header.h"
    using namespace std;
    int variable;
    void function()
    {
    cout << "Words" << endl;
    cout << endl;
    cout << "variable = " << variable << endl;
    }
    Slinky + Escalator = Everlasting Fun!

  5. #5
    1,627
    posts
    hugeExplosions = true;
    Hmm not sure it looks ok, not sure about using system("PAUSE") - this is a Windows sytem you are compiling for?

    Also why don't you just pass variable into function() instead of declaring it external and throwing it about via the header?
    MS Paint FTW!


  6. #6
    Quote Originally Posted by Charleh View Post
    Hmm not sure it looks ok, not sure about using system("PAUSE") - this is a Windows sytem you are compiling for?

    Also why don't you just pass variable into function() instead of declaring it external and throwing it about via the header?
    If I don't put system("PAUSE"); then the console appears and immediately disappears.

    About the external in the header, I know it is a stupid idea, but I just did that as an example so that I can learn how to do it.
    Slinky + Escalator = Everlasting Fun!

  7. #7
    If I don't put system("PAUSE"); then the console appears and immediately disappears.
    If you are using Visual Studio, then you can run the program without debugging it (Ctrl+F5) and the console window won't close itself.

    Nothing else in your program would take a few seconds to generate an error, so system("PAUSE") probably is the cause.

  8. #8
    Well, I'm using Dev-C++. I think I figured it out though. I completely re-did the coding and although it is much longer, it seems to work. I still have system("PAUSE"); at the end, so I'm kind of confused with how it works.
    Slinky + Escalator = Everlasting Fun!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

Home About kirupa.com Meet the Moderators Advertise

 Link to Us

 Credits

Copyright 1999 - 2012