I have this book programming for dummies and they gave a code I want to make sure the code is good and how do I see it on screen here is the code:
#include <iostream>
#include <stdio.h>
int main ()
{
cout << "It works!\n";
cout << "\nPress ENTER to contiune..." << endl;
getchar();
return 0;
}
Am I writing it right and what button do I push to see it and and is the code right??? I have no idea how to see what I wrote what do I press so new to this and I am scared.
did you receive any sort of documentation with your software?
btw the code itself looks solid, although I rarely mess with stdio.h.. if you remove "#include <stdio.h>" and "getchar();" you may find it still does what you want on execution.
I hit it and it is not letting me, they are saying line number 5
5 C:\Users\\Desktop\Seeifworks.cpp `cout' undeclared (first use this function)
(Each undeclared identifier is reported only once for each function it appears in.)
6 C:\Users\\Desktop\Seeifworks.cpp `endl' undeclared (first use this function)
I have no idea what this means and do I need a new complier?
hmm. it really should work if all the include and header files are in the right place.. could ya post the code with "using namespace std;" included and exactly what the errors are when you try to compile. Here's what i'd try.
#include <iostream>
using namespace std;
int main()
{
cout << "It works!\n\nPress ENTER to continue\n";
return 0;
}
if it won't compile that code exactly then yeah you've got a problem with something else
and if there's a free compiler out there let me know lol I'd love to have it I am using educational version but can't legally distribute the executables developed with it
my understanding is it tells the compiler to reference elements from the c++ std library.. Some people don't use it, instead prefixing certain statements with std:: (e.g: "std::cout << string;" instead of "using namespace std; cout << string;")
however, if you use cin, cout, and other std library entities more than once or twice in your program, it makes the code look kinda bleh to me, so just use:
"using namespace std;" and you won't have to worry about saying "std::" before everything
hope that made sense lol I don't know that much about it