Results 1 to 18 of 18

Thread: Need help with my Hello World app.

  1. #1
    Join Date
    Apr 2006
    Location
    I live in NH
    Posts
    611
    Mentioned
    1 Post(s)
    Quoted
    0 Post(s)

    Need help with my Hello World app.

    Need help with my Hello World app. I'm using the Dev C++ compiler.

    Code:
    #include <iostream.h>
    int main()
    {
      cout << "Hello World!";
      system("Pause");
      return 0;
    }
    What am I doing wrong? The only thing that shows up is command prompt paused. But it doesn't output "Hello World!". Why is that? I also tried using printf instead of cout, but I got the same result.

    Thanks for the help.

  2. #2
    Join Date
    Feb 2007
    Posts
    3,616
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    try this:
    SCAR Code:
    program New;
    begin
    Writeln('Hello world');
    end.
    lol, thats easier then C++ if you ask me

  3. #3
    Join Date
    Feb 2007
    Location
    USA
    Posts
    667
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Lol. Jad, he is writing in C++, not anything to do with scar!

    Ron, try doing this.

    cout << "Hello World!"<<endl;

  4. #4
    Join Date
    Feb 2007
    Posts
    3,616
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Quote Originally Posted by omgh4x0rz View Post
    Lol. Jad, he is writing in C++, not anything to do with scar!

    Ron, try doing this.

    cout << "Hello World!"<<endl;
    Lol i knew that I know what C++ is, just don't know how to write it

  5. #5
    Join Date
    Apr 2006
    Location
    I live in NH
    Posts
    611
    Mentioned
    1 Post(s)
    Quoted
    0 Post(s)

    Default

    This code seems to work properly. I just need a way to output information like Hello World, and it seems to work for everyone else but me.

    Code:
    #include <windows.h>
    
    int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, 
        LPSTR lpCmdLine, int nCmdShow)
    {
        MessageBox(NULL, "Yeeaaaaaaahhhhh!", "Yay!", MB_OK);
        return 0;
    }
    The code is not the problem. I'm guessing I have to check some setting or something to get this work. Because it does compile successfully, it just doesn't seem to know what window to output to, or I just don't know which window it is outputting to.

  6. #6
    Join Date
    Nov 2006
    Posts
    18
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Quote Originally Posted by Ron View Post
    Need help with my Hello World app. I'm using the Dev C++ compiler.

    Code:
    #include <iostream.h>
    int main()
    {
      cout << "Hello World!";
      system("Pause");
      return 0;
    }
    What am I doing wrong? The only thing that shows up is command prompt paused. But it doesn't output "Hello World!". Why is that? I also tried using printf instead of cout, but I got the same result.

    Thanks for the help.
    You may need to use using namespace std; or std::cout

    EX:

    Code:
    #include <iostream.h>
    using namespace std;
    
    int main()
    {
      cout << "Hello World!";
      system("Pause");
      return 0;
    }
    OR

    Code:
    #include <iostream.h>
    
    int main()
    {
      std::cout << "Hello World!";
      system("Pause");
      return 0;
    }
    I would try it, but I no longer have MSVC++ 2005 nor Dev-CPP since I just reformatted. Sorry. ( should work though )

  7. #7
    Join Date
    Apr 2006
    Location
    I live in NH
    Posts
    611
    Mentioned
    1 Post(s)
    Quoted
    0 Post(s)

    Default

    Same problem. Thanks any way KuJi.

  8. #8
    Join Date
    Feb 2007
    Location
    USA
    Posts
    667
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Unless you have this <<endl; closing off "hello world", then it will appear on the same line as "press any key to continue" maybe you just looked quickly and didn't see it?

  9. #9
    Join Date
    Sep 2006
    Location
    New Jersey, USA
    Posts
    5,347
    Mentioned
    1 Post(s)
    Quoted
    3 Post(s)

    Default

    I think it's one of your settings; I'm using Bloodshed Dev-C++ (v4.9.9.2), and it worked fine. And it does print everything on one line...

    Code:
    #include <iostream.h>
    int main()
    {
      cout << "Hello World!" <<endl;
      system("Pause");
      return 0;
    }
    EDIT: yay 400th post
    Interested in C# and Electrical Engineering? This might interest you.

  10. #10
    Join Date
    Apr 2006
    Posts
    710
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Ron, does your command prompt close after you execute program?

    If so, you have to start command prompt by going to Start -> Run
    then type:
    1. If you're on w98 -> command
    2. if you're on w2k-wXP -> cmd

    then go to your directory, compile program and execute it.

    Let's say your compiler is cc.exe and you have it's directory in your global path, then you do cc program.cpp

    it outputs program.exe
    now just type program or program.exe and it should execute and give you output without closing command prompt ;-)

  11. #11
    Join Date
    May 2006
    Posts
    6
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    cout shouldn't have even worked unless namespace std was used,

    Code:
    #include <cstdlib>
    #include <iostream>
    You'll need too have those two defined and
    Code:
    using namespace std;

  12. #12
    Join Date
    Nov 2006
    Posts
    48
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    you are starter with c++ ?

  13. #13
    Join Date
    Mar 2007
    Posts
    50
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Unless you have this <<endl; closing off "hello world", then it will appear on the same line as "press any key to continue" maybe you just looked quickly and didn't see it?
    The press any key to continure is in java, not c++, now you do need the system("Pause"); otherwise (as i remember my first week into c++), it will just close automatically, or try makking an input

    Code:
    #include <cstdlib>
    #include <iostream>
    
    int main()
    {
    char um2[5]={'I', 'L', 'U', 'V', 'U'};
    int num=0;
    for(int counter=0; counter<5; counter++)
    {
    if (counter==1)
    {
    cout << " ";
    }
    cout << um2[counter];
    }
    cout <<"\nEnter a number plz : ";
    cin >> num;
    }
    the using namespace std
    and including the << endl;, but after all that i forget, its been a year sense ive used c++, ive been using java
    lol
    system.out.println("Java alot easier for me then c++, lol\n\n\n");

  14. #14
    Join Date
    Jan 2007
    Posts
    23
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    The program is closing just after being ran because there's nothing to stop it from doing that.
    You have two easy options:
    The first is doing a system("pause"). Note that this function is windows only. It is either accessible by default or in stdlib.h.
    The second option, is using a function such as getch().


    About namespaces (std)

    The C++ standard now says that the standard library has to be wrapped into a namespace called std. A few years ago, it wasn't. Back then, a hello world would be:

    #include <iostream.h>
    int main(void) { cout << "hello"; system("pause"); return 0; }

    In modern compilers, however, this WILL NOT compile, because <iostream.h> is outdated, and isn't even included anymore in many of the modern ones, such as MSVC .NET 2005.

    Now, a hello world is like this:
    #include <iostream>
    using namespace std;
    int main(void) { cout << "hello"; system("pause"); return 0; }

    Although you might think that the only thing that changed was the "using namespace std" line, <iostream> and <iostream.h> are not the same files.
    C++ standard library headers (Warning, only C++'s, C's remain unchanged) don't have .hs anymore. They are now <iostream> <fstream> <string> <vector> etc, and they are all wrapped now into a namespace called std.

  15. #15
    Join Date
    Feb 2007
    Location
    SparklesProd.com
    Posts
    2,406
    Mentioned
    1 Post(s)
    Quoted
    0 Post(s)

    Default

    haha at this topic title, made me rofl.

    Will edit this post a bit please with code you can try.

  16. #16
    Join Date
    Apr 2007
    Posts
    36
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Wow wtf...dude do this.

    Code:
    #include <iostream>
    #include <conio.h>
    
    using namespace std;
    
    int main()
    {
         cout << "Hello World" << endl;
    
    getch();
    return 0;
    }
    getch() found in conio.h will stop it from closing.

  17. #17
    Join Date
    Jul 2007
    Location
    Massachusetts
    Posts
    896
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    You have to Say

    Using Namespace std;

    Also, you iostream include is incorrect, try

    #include <iostream>

    (take away the .h)

    Good Luck in learning C++!

  18. #18
    Join Date
    Apr 2007
    Posts
    3,152
    Mentioned
    3 Post(s)
    Quoted
    1 Post(s)

    Default

    i know u meant well, but its been almost 4 months since that last post (im not sure it would take him 4 months to make a hello world)

    NOOBNOOBNOOBNOOBNOOBNOOBNOOBNOOBNOOBNOOBNOOBNOOB
    You, Macrosoft, have been reported for being a NOOB.
    Your
    Current violations include
    1. Grave Digging for
    This brings you to a new total of (2) Noob Points!

    For more information on Macrosoft please go Here.

    For more information from This database please go Here.

    For more information on The Noob Points System please go Here.

    For more information on Noobs please go Here.

    NOOBNOOBNOOBNOOBNOOBNOOBNOOBNOOBNOOBNOOBNOOBNOOB


    edit: if u dont already know, the points will gradually go away
    SCAR Tutorials: The Form Tutorial | Types, Arrays, and Classes
    Programming Projects: NotePad | Tetris | Chess


Thread Information

Users Browsing this Thread

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

Similar Threads

  1. hello world
    By hello world in forum Who Are You ? Who ? Who ?
    Replies: 10
    Last Post: 02-18-2009, 12:40 AM
  2. Hello world
    By marpis in forum Who Are You ? Who ? Who ?
    Replies: 3
    Last Post: 09-08-2008, 01:33 PM
  3. hello world!
    By thewhiteguy in forum Who Are You ? Who ? Who ?
    Replies: 0
    Last Post: 02-03-2007, 05:51 PM

Posting Permissions

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