Results 1 to 16 of 16

Thread: C++ problem

  1. Default C++ problem


    So I was trying out a hello world program. The code is as follows:

    // A Hello World program
    #include <iostream>
    int main() {
    std::cout << "Hello, world!\n";
    return 0;
    }

    After debugging, basically shows hello world on a command print for the briefest of seconds and then vanishes. What's up with that? When I was using c# the command prompt window would stay open until I exited it. Is there a way to keep the hello world window open longer?

  2. Default


    Either run it directly from cmd or there should be a setting in whatever IDE you're using to prevent the window from being closed right away.

  3. Default


    I'm using Microsoft visual c++. Do you know where the relevant buttons might be found?


  4. Default


    For visual C++ if you want for the command prompt to stay then you need to add keep_window_open()
    ie:
    int main() {
    //your code
    keep_window_open();
    return 0;
    }

  5. Default


    ^ i'll try that, thanks.

    How?

  6. Certified Pimento Bi Male
    IGN: xxxxFenixR
    Server: Bera
    Level: Mix
    Job: Severals
    Guild: None
    Alliance: Nada
    Farm: Wut?
    venezuela

    Default


    mmm System Pause or something along those lines? I forgot, not practicing my coding religiously takes a dent on me (Especially since the last time i touched C++ was a year ago)

  7. Default


    Click in the left margin of the line. A red circle will appear. When you debug into the program with Visual Studio, the program will pause when execution reaches that point and you can hover over variables to inspect them and do all kinds of debugging stuff. You can press F5 to resume the program.




    That's assuming you only want it to pause when debugging it. If it was an actual program and you wanted it to pause before exiting, you would do something like write "Press enter to exit." and then read in a line of input.

  8. Default


    Ooh, this has been bugging me too.

    In labs for school, I wasn't allowed to read extra input to act as a "Press ENTER to exit" thing, so I ended up just running it in my own IDE where it works fine (for the record, I use Eclipse).

  9. Default


    Do NOT use system("pause"), using system("whatever") is in most cases the mark of the noob coder. Just saying.
    Alternatively to keep_window_open(), you can create your own keep_window_open() by doing this:
    int main() {
    //your code
    string quit="";
    while(quit!="quit") cin>>quit; //wait until "quit" is written and entered before exiting.
    }

  10. Certified Pimento Bi Male
    IGN: xxxxFenixR
    Server: Bera
    Level: Mix
    Job: Severals
    Guild: None
    Alliance: Nada
    Farm: Wut?
    venezuela

    Default


    Everyone must start someplace and i started with System ("pause"). Saying it marks a noob coder makes it sound offensive you know that?

  11. Default


    Didn't mean to make it sound offensive. Sorry :x

  12. Default


    In Visual Studio, you right click on the project, select properties, go to configuration properties, linker, system, make sure the property SubSystem is CONSOLE (/SUBSYSTEM:CONSOLE).

    This should work for when you run without debugging.

    If you are debugging then you should have break points set anyway.

  13. Default


    @Nr Don't worry I am an inexperienced ('noob') coder anyways.

    How do you know where to put them?

  14. Certified Pimento Bi Male
    IGN: xxxxFenixR
    Server: Bera
    Level: Mix
    Job: Severals
    Guild: None
    Alliance: Nada
    Farm: Wut?
    venezuela

    Default


    Usually a few steps behind what you suspect/know its failing, then you go line by line after that to find exactly whats wrong. Debugging its a very personal thing (At least i remember someone saying this somewhere :P), everyone doesnt necesary do it in a similar way you just need to get some practice in it.

  15. Default


    Wherever you want the program paused.

  16.  

Bookmarks

Posting Permissions

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