Thread: Hello World won't work.

  1. #1
    Registered User
    Join Date
    Apr 2006
    Posts
    8

    Hello World won't work.

    Hello,

    Im new here and just started to try and program. i downloaded the "Dev.C++4" from bloodshed and it works fine. But when i typed up the "Hello World" program found on this site it wont let me run the program. I typed it in perfectly so i know that that isint the problem because it compiled nicely. How do i go about running this program? i compiled it then i clicked on the "setup creator icon" and followed that and it won't let me run the program when i click the application icon im my documents.
    any help is greatly appreciated, thanks, sry for a newbie Question.

  2. #2
    Devil's Advocate SlyMaelstrom's Avatar
    Join Date
    May 2004
    Location
    Out of scope
    Posts
    4,079
    Perhaps it's not that it won't run, it's just that the window is disappearing before you see it. Dev-C++ does that.

    Look at this for a fix: FAQ > How do I... (Level 1) > Stop my Windows Console from disappearing everytime I run my program?
    Sent from my iPad®

  3. #3
    Registered User
    Join Date
    Apr 2006
    Posts
    8
    Thanks alot, i used the C++ Implementation using get(), and the DOS window poped rite up. but Hello World was displayed right after "Press [Enter] to continue" in the DOS window, with no spaces. should Hello World have a space after that or should it be on a new line, or is it supposed to be like it is now like this "Press [Enter] to continueHello World"?
    thanks alot.

  4. #4
    Registered User
    Join Date
    Nov 2005
    Posts
    545
    try this:

    Code:
    include <iostream>
    
    using namespace std;
    
    int main {
    
    cout << "Hello World\n";                    //  \n creates a new line
    cout << "Hello World" << endl;          // endl is another way to make a new line
    cout << "\n\n";                                   // creates two new lines before saying Press [ENTER]
    cout << "Press [ENTER] To Continue";
    cin.get();
    
    return 0
    }
    Plonk that into your compiler.

  5. #5
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    What does your simple code look like? The example in the FAQ uses cout to output the "Press [Enter] to continue" part, so it doesn't make sense for it to come before the Hello World.

  6. #6
    Registered User
    Join Date
    Nov 2005
    Posts
    545
    He must have just put the cin.get() stuff before Hello World.

    Just take a look at my code as it shows putting in new lines.

  7. #7
    Registered User
    Join Date
    Apr 2006
    Posts
    8
    i dont get this, now when i go to even copy and paste a part of code directly from this site it trys to tell me that there are 2 errors. i know that there is not because i copied and pasted them
    what should i do know?
    thanks for any info.

  8. #8
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    Paste the code you copied into code tags and post it here (code tags are [code]paste code here[/code]).

    Then paste the 2 error messages exactly as they show up for you.

  9. #9
    Its hard... But im here swgh's Avatar
    Join Date
    Apr 2005
    Location
    England
    Posts
    1,688
    Or do this using getchar()

    Code:
    #include <iostream>
    
    using std::cout;
    using std::endl;
    
    int main()
    {
    cout << "Hello World!" << endl;
    
    getchar();  // waits for key press
    
    return 0;
    }

  10. #10
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    getchar() is a C function. It's defined in <cstdio>, which you'll need to include if you want to use it.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  11. #11
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    i dont get this, now when i go to even copy and paste a part of code directly from this site it trys to tell me that there are 2 errors. i know that there is not because i copied and pasted them
    what should i do know?
    Well, if you copy some C++ code and save it as a .c file, you'll get some errors.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  12. #12
    Registered User
    Join Date
    Apr 2006
    Posts
    8
    it seems as like it works when it wants to and other times it wont. here is the code that i used. it is a little different than the example shown here on the site.

    Code:
    #include <iostream>
    
    using namespace std;
    
    int main()
    {
      cout << "Hello World!" << endl;
    
      cout << "Press ENTER to continue..." << endl;
      cin.get();
      return 0;
    }

  13. #13
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    So does that code work? If not, what are the errors? It looks correct to me, but you mentioned two errors so you should post the errors you get.

    Make sure you post the exact code that you use and the exact errors you get. Even minor differences can cause problems. The code you just posted looks fine, so if and when you get the errors you don't understand that is when you need to post them and the code.

  14. #14
    Registered User
    Join Date
    Apr 2006
    Posts
    22

    Question

    Quote Originally Posted by GeForzme
    it seems as like it works when it wants to and other times it wont. here is the code that i used. it is a little different than the example shown here on the site.

    Code:
    #include <iostream>
     
    using namespace std;
     
    int main()
    {
    cout << "Hello World!" << endl;
     
    cout << "Press ENTER to continue..." << endl;
    cin.get();
    return 0;
    }
    that didn't work? maybe it's a dev-c++ problem because there's certainly nothing wrong with that. I ran with my compiler ( i use the win32 port of mingw ) and it worked fine. I would suggest getting a new copy of dev-c++ because the problem is certainly not your code.

  15. #15
    Registered User
    Join Date
    Nov 2005
    Posts
    545
    Well I use that exact same version of Dev-C++ and it works fine for me.

    Maybe it is something to do with how he is making the file...ie creating a c style project or something.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Developers Wanted
    By Quasicom in forum Projects and Job Recruitment
    Replies: 2
    Last Post: 08-24-2005, 12:46 AM
  2. Novice Beginner: Simple hello world wont work
    By hern in forum C++ Programming
    Replies: 8
    Last Post: 06-25-2005, 12:16 PM
  3. OpenGL coordinates
    By Da-Nuka in forum Game Programming
    Replies: 5
    Last Post: 01-10-2005, 11:26 AM
  4. Too much to ask ?
    By deflamol in forum C Programming
    Replies: 2
    Last Post: 05-06-2004, 04:30 PM