Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 10 of 10
  1. #1
    New Coder
    Join Date
    Sep 2007
    Posts
    20
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Help with hello world C++ program please.!

    Heres the code I did
    #include <iostream>;

    int main()
    {
    cout << "Hello World"/n;
    cout << "I want to be a programmer"/n;
    cin.get();
    }

    and here are the errors...In function `int main()':
    error: `cout' undeclared (first use this function)
    error: (Each undeclared identifier is reported only once for each function it appears in.)
    error: `n' undeclared (first use this function)
    error: `cin' undeclared (first use this function)

    Execution terminated

  • #2
    Regular Coder
    Join Date
    May 2006
    Location
    Wales
    Posts
    820
    Thanks
    1
    Thanked 82 Times in 79 Posts
    Code:
    #include <iostream>;
    using namespace std;
    
    int main()
    {
    cout << "Hello World\n";
    cout << "I want to be a programmer\n";
    int get;
    cin >> get;
    }
    I think that's right, haven't used C++ for a while

  • #3
    Senior Coder
    Join Date
    Aug 2002
    Location
    Kansas City, Kansas
    Posts
    1,518
    Thanks
    0
    Thanked 2 Times in 2 Posts
    Code:
    #include <iostream>
    using namespace std;
    
    int main()
    {
      cout << "Hello World\n";
      cout << "I want to be a programmer\n";
      int get;
      cin >> get;
      return 0;
    }
    There's no semicolon after include statements, you need to include the proper namespace, and you need to have a return statement. Some of those may be nitpicky and the program could work without them, but they're a good idea. The namespace is definitely needed.

  • #4
    New Coder
    Join Date
    Sep 2007
    Posts
    20
    Thanks
    1
    Thanked 0 Times in 0 Posts
    what does the namespace code do and is cin.get() and cin >> get different? Also, I never seen a int get code what is that?
    Last edited by xsubxwooferx; 10-01-2007 at 12:39 AM.

  • #5
    Regular Coder Aradon's Avatar
    Join Date
    Jun 2005
    Location
    USA
    Posts
    734
    Thanks
    0
    Thanked 20 Times in 19 Posts
    Quote Originally Posted by xsubxwooferx View Post
    what does the namespace code do and is cin.get() and cin >> get different? Also, I never seen a int get code what is that?
    Let me answer the parts that I know.

    The namespace std part allows you to call objects like cin, cout, etc. without having to place an std::cin in front of it (Later in your c++ career you're learn what's up with that)

    Uh, I'm unsure of the second and first. My impression is that with cin.get you are able to place a primative inside the get() and it will return it. So if you just put in a char in cin.get it will get a character (whitespace or otherwise).

    While a cin >> will take the input, buffer it ignoring most whitespace, and place it in whatever object you throw it into.

    As for int get; What he is doing is declaring a variable get (which has an int type) and then using cin to assign to it. As you go past hello world you'll learn all about variables, tricks of input and output in c++ and various other things that will help this all make sense.

    Promise
    "To iterate is human, to recurse divine." -L. Peter Deutsch

  • #6
    New Coder
    Join Date
    Sep 2007
    Posts
    20
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Well i'm not in college yet.I still got couple months of highschool before I think about going into Computer science..I am just seeing what I am getting myself into.Would learning to program easy like when you go into a higher grade like where you don't think you will be able to handle it but when you get their you can?

  • #7
    Gox
    Gox is offline
    Regular Coder Gox's Avatar
    Join Date
    May 2006
    Location
    Ontario, Canada
    Posts
    392
    Thanks
    2
    Thanked 20 Times in 20 Posts
    To be honest, just about every Computer Science course I've taken looked insane when I browsed the course website before taking the class. I found however, that things weren't so bad once I was in the class and the material was being taught to me.

    Just make sure you know what you're getting yourself into. I was not prepared for the amount of theory that would be required of me in a Computer Science program.

  • #8
    New Coder
    Join Date
    Sep 2007
    Posts
    20
    Thanks
    1
    Thanked 0 Times in 0 Posts
    I know what I think I am getting into which is alot of hard work and non stop learning after college cause of the changes in technology. Is that right? Also, I am thinking of going into software engineering or so.Which would be more useful? C++ or java? I see some jobs around here just say they want a programmer but don't specify what kind.
    Last edited by xsubxwooferx; 10-01-2007 at 11:32 PM.

  • #9
    Regular Coder DELOCH's Avatar
    Join Date
    Apr 2006
    Location
    Canada
    Posts
    537
    Thanks
    4
    Thanked 2 Times in 2 Posts
    C++ is good for applications

    Java is great for web applets.

    Both can make applications but java is a bit... less preferred by users...

    but many great applications been made with java and have been used but c++ is much more effective...

    most people don't know what .jar files are anyway...

  • #10
    New Coder
    Join Date
    Sep 2007
    Posts
    20
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by DELOCH View Post
    C++ is good for applications

    Java is great for web applets.

    Both can make applications but java is a bit... less preferred by users...

    but many great applications been made with java and have been used but c++ is much more effective...

    most people don't know what .jar files are anyway...
    Great that makes it easy on my part. Also, I got the Hello world from what you guys on this page left me and I got that memorized down pat whether that is good or bad I dunno cause I don't really know what the coding means exactly but have sorta of an idea.


  •  

    Posting Permissions

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