Jump to content
  • Advertisement
Sign in to follow this  
Haku

help a noob out

This topic is 5400 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

Ok i started learning c++ yesterday here is a piece of code i have written, why does it not compile and run, i use borland c++ builder 5 #include <iostream.h> int main () { int x=5; int i; cout << "enter the number five"; cin >> i; if (i==x) cout << "well done!"; else cout << "i said type five dumbass"; return(0); }

Share this post


Link to post
Share on other sites
Advertisement
Worked fine for me. <iostream.h> is depracated. Use <iostream> and then using namespace std;


#include <iostream>
using namespace std;

int main ()
{
int x=5;
int i;

cout << "enter the number five";
cin >> i;

if (i==x)
cout << "well done!";
else
cout << "i said type five dumbass";
return(0);
}

Share this post


Link to post
Share on other sites
oh boy...
1) iostream.h is a non-standard header, use iostream.
2) what errors do you get?

#include <iostream>
#include <ostream>
#include <istream>
using std::cin;
using std::cout;

int main ()
{
int x = 5;
int i;

cout << "enter the number five";
cin >> i;
if (i==x)
cout << "well done!";
else
cout << "i said type five dumbass";
return 0;
}


Share this post


Link to post
Share on other sites
i think it might be my compiler, it says "unresolved external form", any compilers you would recommend?

Share this post


Link to post
Share on other sites
Hrm, seeing the error would be much more helpful. You could use Visual C++ 2003. Or GCC or DevC++...

Share this post


Link to post
Share on other sites
Quote:
Original post by Washu
Hrm, seeing the error would be much more helpful. You could use Visual C++ 2003. Or GCC or DevC++...


ok, is devc++ shareware/freeware and what is the difference between iostream.h and iostream?

Share this post


Link to post
Share on other sites
iostream.h doesn't exist in the context of the standard. iostream does however. DevC++ and variants are free. Visual C++ 2003 is not, but the CLI compiler/linker is.

Share this post


Link to post
Share on other sites
Yes, dev-C++ is free. Go here to download it. And it would definitely help if you posted what error you're getting, exactly. Chances are somebody else has gotten it.


EDIT: link fixed

Share this post


Link to post
Share on other sites
the link u gave me was incorrect and for the original code i posted do you really need to add the other #includes

EDIT: the #includes i meant were #include <ostream>
#include <istream>
using std::cin;
using std::cout

Share this post


Link to post
Share on other sites
Quote:
Original post by Haku
the link u gave me was incorrect and for the original code i posted do you really need to add the other #includes

Yes, iostream will declare cin and cout, but might not define them in any other regards (most libraries do however).

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • 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!