Public Group

#### Archived

This topic is now archived and is closed to further replies.

# Hello world C++ program problem

This topic is 5649 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hi, I''m new at C++ but I thought I wasn''t until someone pointed out I was using C the whole damn time... Oh well I''ll use C as an advantage. Well I am trying to make a simple AND I QUOTE "C++" program and it keeps saying cout is unsinged and some other stuff. My compiler is acting like I''m making that damn language up or something. Here''s the code I won''t put down the errors from compiling it cuz I got 319 of em... HELP ME! #include <windows.h> #include <stdio.h> #include <stdlib.h> //I fixed like 40 errors by discluding iostream.h int main (int argc, char *argv[]) { cout << "Hello World!" << endl; cout << "Press ENTER to continue..." << endl; getchar (); return 0; }

##### Share on other sites
Wow, 319 errors? I'm impressed Quite a few for such a small program, I don't even know how that's possible. Are you sure it's "safe" to not include iostream.h? You'll need it for cout<<. The only possbility I can think of is that the other #includes #include iostream themself... just a thought. And btw, I don't think you need to include windows.h.

Back to the problem... code looks fine at first glance. I don't see anything wrong with it. Could you post a few examples of the errors you're getting?

Peon

[edited by - Peon on April 1, 2003 12:15:43 AM]

##### Share on other sites
This is what I said in the console math thread: Unsigned means it can''t be negative (ie the - sign), but if you mean undefined, try including iostream and adding the line
using std::cout. Yes, iostrea.h also works, and you don''t need the using std::cout with it, but iostream is depricated so not all compilers have it.

-~-The Cow of Darkness-~-

##### Share on other sites

  // You -need- this for cout#include <iostream>// This should fix some errors (bad style, but OK for a newbie ;)using namespace std;int main() // No need for args unless you mean to use them{    cout << "Hello world" << endl;}

Note that you do not need windows.h; moreover, in this program there is no reason to include stdio.h or stdlib.h (and furthermore, in C++, you should use cstdio and cstdlib -- without .h suffix -- instead). Like I said, though, you need iostream because this is where cout is defined. Finally, you don't need to return 0 from main() -- main() is a special case in that, although it must return an integer, you don't have to explicitly return anything; unless otherwise specified it will return 0.

[edited by - Miserable on April 1, 2003 12:20:48 AM]

##### Share on other sites
Holy crap. You told me to get rid of the #include <windows.h> and it worked! Only 5 errors now, I''ll list them

helloworld.cpp: In function int main(int, char**)'':
helloworld.cpp:6: cout'' undeclared (first use this function)
helloworld.cpp:6: (Each undeclared identifier is reported only once for each

function it appears in.)
helloworld.cpp:6: endl'' undeclared (first use this function)

##### Share on other sites
looks like you''re still missing an iostream file.

-~-The Cow of Darkness-~-

##### Share on other sites

    #include <iostream.h> // cout, cin, etc..#include <conio.h>    // getch()int main(){        cout << "Hello World!" << endl;        cout << "Press ENTER to continue..." << endl;        getch();        return 0;}  `

As far as I know, getchar() doesn't exsist. You need conio.h for getch(), and you don't need windows.h since this is a consol app. stdio and stdlib are also not necessary for this app. the argc etc.. in the main function are optional and for something this simple, you don't need them.

[edited by - TheBlackJester on April 1, 2003 12:23:32 AM]

##### Share on other sites
Miserable and BlackJester sorry but your advice and code got me 81 errors... LOL

##### Share on other sites
getchar certainly exists... I use it all the time...

-~-The Cow of Darkness-~-

##### Share on other sites
My bad cow, just shows how much i DON''T program in consol mode

WaterMelon: It would be of great assistance of you could post some of your errors!

1. 1
2. 2
Rutin
22
3. 3
4. 4
frob
17
5. 5

• 33
• 13
• 12
• 10
• 12
• ### Forum Statistics

• Total Topics
632575
• Total Posts
3007152

×