CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 9 of 9
  1. #1
    Join Date
    Jun 2010
    Posts
    4

    Beginner Question

    Ok I'm very new to this but generally a fast learner (taught myself HTML and Java within months) but I'm having the most basic of issues.

    I used a program years ago when I first dabbled in programming, just to run this basic program:

    -----
    // my first program in C++

    #include <iostream>
    using namespace std;

    int main ()
    {
    cout << "Hello World!";
    return 0;
    }
    ------

    just he bog standard first program. I'd write it, run it and see it... However these days I'm using Microsoft Visual C++ 2010 Express. I've written the program but can't find a feature ANYWHERE to actually RUN the program? I've read their help guides, scanned the net and can't seem to find anything that works and runs the program, showing me my text?

    Can anybody help or point me in the direction of a program that isn't packed with bloatware? (This program seems to have ten billion things a beginner doesn't need and doesn't explain what half of it even is)

    Thanks

  2. #2
    Join Date
    Oct 2009
    Posts
    13

    Re: Beginner Question

    make sure ur in the right solution platform (ie win32). The solution configuration should be " Debug", and just press F5 to run. Both the solution platform and the solution configuration are drop down boxes in the toolbar.

  3. #3
    Lindley is offline Elite Member Power Poster
    Join Date
    Oct 2007
    Location
    Seattle, WA
    Posts
    10,895

    Re: Beginner Question

    You want the "Start Debugging" or "Start Without Debugging" menu options in the Debug menu.

  4. #4
    Join Date
    Jun 2010
    Posts
    4

    Re: Beginner Question

    My set up doesn't seem to have 'Start without debugging' only 'Start debugging'

    Anyhow, thats what I assumed I'd have to press, so I have done and it just comes up with this in the output...

    '1st Program.exe': Loaded 'C:\Documents and Settings\Damian\My Documents\Visual Studio 2010\Projects\1st Program\Debug\1st Program.exe', Symbols loaded.
    '1st Program.exe': Loaded 'C:\WINDOWS\system32\ntdll.dll', Cannot find or open the PDB file
    '1st Program.exe': Loaded 'C:\WINDOWS\system32\kernel32.dll', Cannot find or open the PDB file
    '1st Program.exe': Loaded 'C:\WINDOWS\system32\msvcp100d.dll', Symbols loaded.
    '1st Program.exe': Loaded 'C:\WINDOWS\system32\msvcr100d.dll', Symbols loaded.
    The program '[3912] 1st Program.exe: Native' has exited with code 0 (0x0).
    The DOS window pops up but vanishes in a split second, then that appears in the output and nothing happens. Anybody know what this PDB thing is... which I assume is the problem?

    Thanks for replying

  5. #5
    Lindley is offline Elite Member Power Poster
    Join Date
    Oct 2007
    Location
    Seattle, WA
    Posts
    10,895

    Re: Beginner Question

    Quote Originally Posted by Damian227 View Post
    My set up doesn't seem to have 'Start without debugging' only 'Start debugging'
    Oh, that's right. For some strange reason Microsoft removed the "Start without debugging" option from the menu by default in 2010. You can re-add it if you edit the menu if you want.

    Anyhow, thats what I assumed I'd have to press, so I have done and it just comes up with this in the output...

    The DOS window pops up but vanishes in a split second, then that appears in the output and nothing happens. Anybody know what this PDB thing is... which I assume is the problem?

    Thanks for replying
    There is, technically, no problem. Your program begins running. It needs a console window to run in, so one is opened. Your program writes its output to the window. Then your program finishes. Since it is no longer running, there is no reason for the console window to remain open, the same way your browser window disappears when you quit the browser.

    FYI, "exited with code 0" almost always means "exited normally." Values other than 0 typically indicate an error.

    If you want to see the output of your program before the window closes, then you need to either run the executable from a pre-existing console window (this is, technically, the "right" solution since this is how console apps are intended to be run, but isn't much help to beginners who are only used the "console app" program type because it's simple), or else you need to prevent the program from exiting until you wish it to do so.

    For this latter approach, you can either set a breakpoint at the end of main since you're using "Start debugging" anyway, or you can add code which waits for user input on the console before exiting. If you select "Start without debugging", Visual Studio will be kind enough to automatically insert such code behind the scenes, but that's just a courtesy, not required behavior.

  6. #6
    Join Date
    Oct 2009
    Location
    NY, USA
    Posts
    191

    Re: Beginner Question

    Use the code as follows and your DOS window would not vanish.

    Code:
    system("pause");
    return 0;
    }

  7. #7
    Join Date
    Jun 2010
    Posts
    4

    Re: Beginner Question

    Thank you both for the info, being able to see the effects of my coding will really help me learn, so that little 'pause' part is bound to help me a great deal.

    My goal is to make a basic 2D side scrolling game for the PC, kind of like Super Mario I guess. No big project, nothing fancy, just to learn the basics and then make a new goal. So obviously being able to see the results helps lol.

    Just out of curiosity, is there a way to export the programs I make, so they can be run outside of the compiler? i.e. an exe as the game would be booted up anyway? It's just I'd like to keep them and be able to send them to my brother to show off (he's keen to learn C++ also)

  8. #8
    Lindley is offline Elite Member Power Poster
    Join Date
    Oct 2007
    Location
    Seattle, WA
    Posts
    10,895

    Re: Beginner Question

    Every compile generates an exe. You just have to go find it (usually in the project directory). It will be easier to redistribute if you change the Project Properties -> C/C++ -> Code Generation setting to link in a non-DLL version of the C Runtime.

  9. #9
    Join Date
    Jun 2010
    Location
    Germany
    Posts
    2,675

    Re: Beginner Question

    Quote Originally Posted by Lindley View Post
    Oh, that's right. For some strange reason Microsoft removed the "Start without debugging" option from the menu by default in 2010. You can re-add it if you edit the menu if you want.
    Or he can simply press Ctrl+F5 which does the same. That's my favorite.

    About the implicit pause or no pause upon return from the console app: This seems to depend on whether you start the app with or without debugging. If the program is run without debugging, the pause is inserted automatically, while if you start with debugging, the IDE appears to assume that you have set one or the other breakpoint and don't need it.

    [CODE=Lindley]
    It will be easier to redistribute if you change the Project Properties -> C/C++ -> Code Generation setting to link in a non-DLL version of the C Runtime.
    [/CODE]

    And aside from that: Don't give away debug builds, as they will only run on systems that have the development package installed. Use release builds instead.

    HTH

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured