...

View Full Version : Help with hello world C++ program please.!



xsubxwooferx
09-30-2007, 07:48 PM
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

Mwnciau
09-30-2007, 08:14 PM
#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

Antoniohawk
09-30-2007, 08:58 PM
#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.

xsubxwooferx
10-01-2007, 01:34 AM
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?

Aradon
10-01-2007, 03:28 AM
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 :)

xsubxwooferx
10-01-2007, 02:06 PM
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?

Gox
10-01-2007, 11:36 PM
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.

xsubxwooferx
10-02-2007, 12:24 AM
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.

DELOCH
10-02-2007, 12:48 AM
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...

xsubxwooferx
10-02-2007, 01:37 AM
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.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum