Tuesday, July 14, 2009

Can i have some help in c++?

i am very new to c++ and programming in general.


i bought a book called c++ all in one desk reference for dummies.


i am a few pages in and im having trouble making words come up into a dos box.





im using a program called dev-c++





#include %26lt;iostream%26gt;


#include %26lt;stdlib.h%26gt;





int main(int argc, char *argv[])


{


cout %26lt;%26lt; "Hello, i am your computer talking." %26lt;%26lt; endl;


system("PAUSE") ;


return 0;


}








when i enter that, the error box on the bottom of dev-c++ says





line 8 message: cout undeclared (first use this function)





line 8 message: endl undeclared (first use this function)





also, if i delete line 8 of that, it works fine, a dos box pops up and says press any key to continue.





if you could please give me a few tips upon what i might be doing wrong,


please tell me!

Can i have some help in c++?
You need to either change line 8 to read:





std::cout %26lt;%26lt; "Hello..." %26lt;%26lt; std::endl;





Or add:





using namespace std;





After the #include lines.





You have to tell the compiler in what namespace to find cout %26amp; endl; the first does it explicitly, the second makes all names in the std namespace available in your program.





Edit to luv l: No, it's not %26lt;iostream.h%26gt;, it's just %26lt;iostream%26gt;. The standard library does not use .h for its headers; the .h versions are deprecated and should no longer be used, as they do not use the std:: namespace.
Reply:You need to specify that your working with the standard c++ namespace.





type in "using namespace std;" before your 'main' function.





alternatively, you could use std::cout %26lt;%26lt;" blah blah"; instead if you preferred, putting the std:: before every cout/ cin / any other standard function.





Im new to c++ too, sorry if my terminology is a bit worng.
Reply:#include %26lt;iostream%26gt;


using namespace std;





int main()


{


cout %26lt;%26lt; "Hello, i am your computer talking." %26lt;%26lt; endl;


system("PAUSE") ;


return 0;


}
Reply:its not iostream


its iostream.h


try this it will work
Reply:firstly, about the cout thing. (i have dev-c++) change the line #include %26lt;iostream%26gt;


to


#include %26lt;iostream.h%26gt;





now you should be aware that a dos box will always pop up (unless you use win32, that's not the case however)


what the system("pause") function does is to display "press nay ...'


No comments:

Post a Comment