Friday, May 21, 2010

Question about C++?

I have a problem with executing a program:





1%26gt;.\temp.cpp(17) : error C2065: 'cout' : undeclared identifier


1%26gt;.\temp.cpp(17) : error C2065: 'endl' : undeclared identifier


1%26gt;.\temp.cpp(24) : error C2065: 'cin' : undeclared identifier





with temp.cpp being my program. How do i declare the identifiers?

Question about C++?
you shouldn't have to. Without a code snippet, its hard to see what's going on.





I suspect you are not doing one of the following:





1) put std:: in front of cout, endl, and cin so they are std::cout for example





2) putting using namespace std; at the top of the file (after includes)





generally: it looks like this:





#include %26lt;iostream%26gt;





int main(int argv, char** argc)


{


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





using namespace std;





cout %26lt;%26lt; "No need to put in std::" %26lt;%26lt; endl;


}


No comments:

Post a Comment