-
Supernoob problem!
Okay, so I'm using g++ and am getting an error that cout is not defined even when I include iostream:
Code:
#include <iostream>
int main() {
cout << "This should show up!" << endl;
return 0;
}
Error:
Code:
testclr.cpp: In function `int main()':
testclr.cpp:2: error: `cout' undeclared (first use this function)
testclr.cpp:2: error: (Each undeclared identifier is reported only once for
each function it appears in.)
testclr.cpp:2: error: `endl' undeclared (first use this function)
-
You've correctly included the 'iostream' header file, but the function 'cout' is part of a namespace within iostream called the std namespace.
After
Code:
#include <iostream>
, you have to put
Code:
using namespace std;
.
Or, when you use 'cout', put this instead : . That tells the compiler which namespace you're using.
-
Yeah, what he said.
Code:
#include <iostream>
using namespace std;
int main()
{
cout<<"This should show up!!!";
return 0;
}
or
Code:
#include <iostream>
int main()
{
std::cout<<"This should show up!!!";
return 0;
}
-
Option #3
Code:
#include <iostream>
using std::cout;
using std::endl;
int main() {
cout << "This should show up!" << endl;
return 0;
}