Thread: Hello World Problem

  1. #1
    Registered User
    Join Date
    Jun 2005
    Posts
    1

    Hello World Problem

    Hi,
    Im new to programming 'n am using Dev C++
    as compiler.Im trying to code the very basic
    Hello World program in it but its giving errors.
    Im referring to the book "Sams Teach Yourself
    C++ in 24 Hours by Jesse Liberty"
    Heres the code:

    Code:
    #include <iostream.h>
    
    int main()
    {
        cout << "Hello World!\n";
        return 0;
    }
    What can the problem be?

    Khotwadi

  2. #2
    Handy Andy andyhunter's Avatar
    Join Date
    Dec 2004
    Posts
    540
    Well, what error are you recieving? Or are you just getting a warning about using deprecated headers?
    i don't think most standard compilers support programmers with more than 4 red boxes - Misplaced

    It is my sacred duity to stand in the path of the flood of ignorance and blatant stupidity... - quzah

    Such pointless tricks ceased to be interesting or useful when we came down from the trees and started using higher level languages. - Salem

  3. #3
    Registered User mrafcho001's Avatar
    Join Date
    Jan 2005
    Posts
    483
    today we do it like this:

    Code:
    #include <iostream>
    using namespace std;
    
    int main()
    {
        cout << "Hello World" << endl;
        return 0;
    
    ----------------------------------------------------
    for your compiler:
    ----------------------------------------------------
    #include <iostream>
    using namespace std;
    
    int man()
    {
    cout << "Hello world" << endl;
    system("PAUSE");              // So the program stop before it exits
    return 0;
    }

  4. #4
    Registered User
    Join Date
    Jun 2005
    Location
    Philadelphia
    Posts
    16
    Could use cin.get(); instead of system("PAUSE"); so you dont have to include windows.h.

  5. #5
    Registered User mrafcho001's Avatar
    Join Date
    Jan 2005
    Posts
    483
    Quote Originally Posted by RedZone
    Could use cin.get(); instead of system("PAUSE"); so you dont have to include windows.h.

    You don't need <windows.h> for system("PAUSE")....

  6. #6
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    Your book is old and outdated. AFAIK the latest edition of that book is the 3rd edition which uses the correct headers. Either buy the latest edition, buy a different, new book (e.g. Accelerated C++ by Koenig & Moo), or spend some time on the net finding out the differences between your book's code and modern, correct code.

    The 3rd edition of the book uses the following code instead. Check out the examples and you might see how to update the rest of your code.
    Code:
    #include <iostream>
    
    int main()
    {
         std::cout << "Hello World!\n";
         return 0;
    }

  7. #7
    Registered User
    Join Date
    Sep 2001
    Posts
    4,912
    His current book is fine as long as he keeps this in mind:

    - You need to use namespaces. Easiest way to do this is just add "using namespace std;" after your #include's. There are other methods, but until you get quite advanced, there is no use for the additional confusion.

    - For standard headers, you drop the ".h" extension. Precede the following headers with a "c" (so, for example, <assert.h> would become <cassert>):

    <assert.h>
    <ctype.h>
    <errno.h>
    <float.h>
    <limits.h>
    <locale.h>
    <math.h>
    <setjmp.h>
    <signal.h>
    <stdarg.h>
    <stddef.h>
    <stdio.h>
    <stdlib.h>
    <string.h>
    <time.h>

    The system() function comes from of <cstdlib>, but you should still replace it with something else. See this for details: http://www.cprogramming.com/tips/sho...ount=30&page=1

  8. #8
    Registered User
    Join Date
    Jun 2005
    Location
    Philadelphia
    Posts
    16
    Quote Originally Posted by mrafcho001
    You don't need <windows.h> for system("PAUSE")....
    If you're doing it the old way like hes doing [#include <iostream.h>] then you need windows.h

  9. #9
    Registered User
    Join Date
    Nov 2004
    Posts
    93
    I have the fifth edition of the 21 days book. It reads exactly..

    Code:
    #include <iostream>
    
    int main()
    {
    std::cout << "Hello World!\n";
    return 0;
    }

  10. #10
    Registered User
    Join Date
    Apr 2003
    Posts
    2,663
    Instead of these hieroglyphics at the top of your program:
    Code:
    #include <iostream.h>
    use these hieroglyphics instead:
    Code:
    #include <iostream>
    using namespace std;
    With some compilers(= the thing you run your programs with), you may have to include a line of code before the last line as well:
    Code:
    ....
       cin.get();  //or system("pause");
       return 0;
    }
    Last edited by 7stud; 06-12-2005 at 01:10 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. searching problem
    By DaMenge in forum C Programming
    Replies: 9
    Last Post: 09-12-2005, 01:04 AM
  2. Bin packing problem....
    By 81N4RY_DR460N in forum C++ Programming
    Replies: 0
    Last Post: 08-01-2005, 05:20 AM
  3. Words and lines count problem
    By emo in forum C Programming
    Replies: 1
    Last Post: 07-12-2005, 03:36 PM
  4. half ADT (nested struct) problem...
    By CyC|OpS in forum C Programming
    Replies: 1
    Last Post: 10-26-2002, 08:37 AM
  5. binary tree problem - help needed
    By sanju in forum C Programming
    Replies: 4
    Last Post: 10-16-2002, 05:18 AM