We're aware that some users are experiencing technical issues which the team are working to resolve. See the Community Noticeboard for more info. Thank you for your patience.
📨 Have you signed up to the Forum's new Email Digest yet? Get a selection of trending threads sent straight to your inbox daily, weekly or monthly!

problem with an exe

Options
hey, since i have a ton of time to kill (cant get a job for the summer ggrrr) i've decided to try and learn C++ (mainly cos i like games :P) and i'm kinda stuck before even starting.

One of the example programs i've got is the all time favourite 'hello world' program... at first i thought i'd made a mistake when typing the code, but the example file won't work either. so heres the problem:

got the example code, Bloodshed Dev-C++ compiles it... and there on my desktop next to the saved cpp file is 'hello_world.exe' ... unfortunetly when i try to run it, command prompt opens and then dissapears instantly. obviously this would stand to be more than a slight problem since i can't actually test the code :@

suggestions appreciated
«1

Comments

  • culpepper
    culpepper Posts: 4,076 Forumite
    you need to add a press any key command so it waits.Cant remember how to do it but either someone else will know on here or just look further into your guide book.
  • garcia
    garcia Posts: 214 Forumite
    Either that or open up a command prompt and execute the program from there. It will then spew out "Hello world" and whatever other expletives you've added before coming back to the command prompt.
  • Chippy_Minton
    Chippy_Minton Posts: 3,339 Forumite
    Open a command window (Start - Run - type in cmd and press return). Now run the exe. cd to its folder for convenience.
  • Lord_Chris
    Lord_Chris Posts: 358 Forumite
    garcia wrote:
    Either that or open up a command prompt and execute the program from there. It will then spew out "Hello world" and whatever other expletives you've added before coming back to the command prompt.

    lol... i didnt add any expletives ...alright, i didnt add many expletives :)

    i tried that, it didnt like it when i tried using prompt to run it it didnt like it.

    any ideas on the any key command please someone... save me reading a book twice :(

    what is it about XP's command prompt? such a !!!!! compared to good ol' 98
  • nickmack
    nickmack Posts: 4,435 Forumite
    Part of the Furniture 1,000 Posts Combo Breaker
    Wait for a keypress in C++

    #include <stdio.h>

    int main(void)
    !!
    int ch;
    printf ("Press [Enter] to continue");
    while ((ch = getchar()) != '\n' && ch != EOF);
    return(0);
    }
  • Lord_Chris
    Lord_Chris Posts: 358 Forumite
    still no joy :(

    wth is going on?

    is there an alternative way to open exe's... like a simulator for programming development? ...probably not im guessing but anyone actually know?

    is the exe meant to close cmd prompt that quickly in XP or is it a problem with mine?

    this is such a (insert a creative expletive of your choice here) nuisance.
  • Chippy_Minton
    Chippy_Minton Posts: 3,339 Forumite
    Lord_Chris wrote:
    is there an alternative way to open exe's... like a simulator for programming development?
    Run it using the integrated d.e.b.u.g.g.e.r in Bloodshed.

    You say the .exe is on your Desktop. To get there open the command window and type:

    cd desktop

    You should now be able to run yourProg.exe and the window will remain open.
  • nickmack
    nickmack Posts: 4,435 Forumite
    Part of the Furniture 1,000 Posts Combo Breaker
    For some reason when I typed the open curly bracket after the int main(void), it has replaced it with !!
  • Lord_Chris
    Lord_Chris Posts: 358 Forumite
    nickmack... i love you so much... not in THAT way, but ya know :)

    on its own the hit enter to continue thing works fine, but how do i combine that with other code?

    for example, this is what the example file for hello world is:
    // Hello World
    // A first C++ program

    #include <iostream>

    int main()
    !!
    std::cout << "Hello World!" << std::endl;
    return 0;
    }

    if you could point out where i need to put the hit enter to contiue bit it would be much appreciated :)

    EDIT: the 2 exclamation marks are the open squiggly bracket thing on mine too :@

    EDIT 2: even though i got it working using Chippy's method, if you wouldn't mind this could be useful later :D
  • Lord_Chris
    Lord_Chris Posts: 358 Forumite
    Run it using the integrated d.e.b.u.g.g.e.r in Bloodshed.

    You say the .exe is on your Desktop. To get there open the command window and type:

    cd desktop

    You should now be able to run yourProg.exe and the window will remain open.

    CHIPPY I LOVE YOU... GENIUS, TY SO MUCH, IT WORKED - YAY
This discussion has been closed.
Meet your Ambassadors

🚀 Getting Started

Hi new member!

Our Getting Started Guide will help you get the most out of the Forum

Categories

  • All Categories
  • 351K Banking & Borrowing
  • 253.1K Reduce Debt & Boost Income
  • 453.6K Spending & Discounts
  • 244K Work, Benefits & Business
  • 598.9K Mortgages, Homes & Bills
  • 176.9K Life & Family
  • 257.3K Travel & Transport
  • 1.5M Hobbies & Leisure
  • 16.1K Discuss & Feedback
  • 37.6K Read-Only Boards

Is this how you want to be seen?

We see you are using a default avatar. It takes only a few seconds to pick a picture.