Discussion:
#include <iostream> ERROR
(too old to reply)
Steve Bby
2006-06-16 17:44:39 UTC
Permalink
I compile a small program below:
********************
#include <iostream>

main()
{
cout << "Test\n";
}
********************

GOT ERROR:
=====================
$ g++ -o bmain bmain.c
bmain.c: In function `int main()':
bmain.c:5: error: `cout' undeclared (first use this function)
bmain.c:5: error: (Each undeclared identifier is reported only once for each function it appears in.)
$

What's wrong. Help please!
Thomas Maeder
2006-06-16 18:50:24 UTC
Permalink
Post by Steve Bby
********************
#include <iostream>
main()
Implicit has been obsolete for very long time now.
Post by Steve Bby
{
cout << "Test\n";
<iostream> declares cout in name std. Refer to that object with the
name std::cout, or use a using declaration or using directive.

More, the operator<< overload for character arrays is declared in the
Standard header <ostream>, not <iostream> (not necessarily anway). In
order to write portable code, #include <ostream> as well.
Vipin Dravid
2006-06-16 18:57:35 UTC
Permalink
cout is declared in namespace std, so either bring it to global
namespace by "using" directive or use explicit qualification:

--snip--
#include <iostream>
using namespace std;

int
main()
{
cout << "Test\n";
return 0;
}

--snip--

Or

--snip--
#include <iostream>

int
main()
{
std::cout << "Test\n";
return 0;
}
--snip--

should compile fine
Post by Steve Bby
********************
#include <iostream>
main()
{
cout << "Test\n";
}
********************
=====================
$ g++ -o bmain bmain.c
bmain.c:5: error: `cout' undeclared (first use this function)
bmain.c:5: error: (Each undeclared identifier is reported only once for each function it appears in.)
$
What's wrong. Help please!
_______________________________________________
help-gplusplus mailing list
http://lists.gnu.org/mailman/listinfo/help-gplusplus
--
Regards,
V i p i n

Life is what happens to you while you are busy making other plans.
- John Lenon
Loading...