Jump to content
  • Advertisement

Archived

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

WaterMelon34

Hello world C++ program problem

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

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
Share on other sites
Advertisement
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!