Results 1 to 6 of 6

Thread: Hello world NOT WORKING?! (solved)

  1. #1

    Thread Starter
    Fanatic Member alkatran's Avatar
    Join Date
    Apr 2002
    Location
    Canada
    Posts
    860

    Angry Hello world NOT WORKING?! (solved)

    ok, heres the code, im sure uve all seen it b4...

    #include <iostream>

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

    When i run the program... nothing happens... isn't it supposed to display hello world to my screen???

    (simplest program and i can't get it right )


    It was just the window disppearing before i could even see it, thanks
    Last edited by alkatran; Jul 31st, 2002 at 04:02 PM.
    Don't pay attention to this signature, it's contradictory.

  2. #2
    Addicted Member
    Join Date
    Nov 2001
    Posts
    163
    either you have to use iostream.h or if you are using iostream

    you have to write
    using namespace std...
    Purushottam

  3. #3
    Frenzied Member Memnoch1207's Avatar
    Join Date
    Feb 2002
    Location
    DUH, Guess...Hint: It's really hot!
    Posts
    1,861
    Code:
    #include <iostream>
    
    int main()
    {
       cout << "Hello World!\n";
       return 0;
    }
    try removing the
    std::
    and use the code above
    Being educated does not make you intelligent.

    Need a weekend getaway??? Come Visit

  4. #4
    PowerPoster abdul's Avatar
    Join Date
    Dec 2000
    Location
    Ontario,Canada
    Posts
    2,827
    If you mean that the screen just closes after about a second, try taking some input before closing like this:
    PHP Code:
    #include <iostream>

    int main()
    {
    int i;   
    cout << "Hello World!\n";
    cin>>i;
       return 
    0;

    Baaaaaaaaah

  5. #5
    Frenzied Member Zaei's Avatar
    Join Date
    Jul 2002
    Location
    My own little world...
    Posts
    1,710
    When you #include <iostream>, you must either include the line "using namespace std;", the lines "using std::<object here>;", or prefix all standard object names with "std::". Here is the hello world program with all three options:
    Code:
    #include <iostream>
    using namespace std;
    
    int main()
    {
        cout << "Hello World!\n";
        return 0;
    }
    Code:
    #include <iostream>
    using std::cout;
    
    int main()
    {
       cout << "Hello World!\n";
       return 0;
    }
    Code:
    #include <iostream>
    
    int main()
    {
       std::cout << "Hello World!\n"; 
       return 0;
    }
    abdul is also correct. If the window simply flashes on and off screen again, try adding an input call like he did.

    Z.

  6. #6
    Fanatic Member MoMad's Avatar
    Join Date
    Oct 2000
    Location
    Seattle, WA
    Posts
    625
    also, try flushing the buffer.

    cout << "blah"; will stay in the buffer untill you flush the buffer into the screen. you have to use endl to flush the buffer or the function flush.

    try:

    PHP Code:
    #include <iostream>

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

    Notice the endl to finish the line, it does more than just add a '\n' at the end. It also flushes the buffer.

    Regards,
    MoMad
    :MoMad:
    Nice Sig!

    http://go.to/momad/ Status: Not Ready

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