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" %26lt;%26lt; endl;
system("PAUSE");
return 0;
}
the compilier is giving me errors for cout and endl stating "undeclared" why is this happening?
if i erase line 6 i can compile and run without a problem
Undeclared error using cout and endl?
you're missing the statement:
"using namespace std;"%26lt;----Type this without quotes. Place this statement after your includes and before int main function
This will give you access to c++ standard functions like cout and endl. Oh and you're fine with %26lt;iostream%26gt;. It was updated from %26lt;iostream.h%26gt; to %26lt;iostream%26gt;
or you could write
std::cout%26lt;%26lt;"Hello"%26lt;%26lt;std::endl;
but if you're not into namespaces right now, then just stick with the first method. It definitely will enlarge your file if you use the second method
Reply:try using ' "\n"; ' instead of endl;
it might be "/n"; i don't remember which way it faces....you can actually do this:
cout%26lt;%26lt; "hello\n;"
(depending on the direction of the slash)
Reply:You can use cout%26lt;%26lt;"hello \n"; as an alternative.. I don't think yours is a wrong statement. May be like in the question u have typed, it is iostream.h (you have misseed the extension .h), try fixing it.
Or the problem may be due to corrupt compiler.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment