Re: Iostream
From: Mike Wahler (mkwahler_at_mkwahler.net)
Date: 10/24/03
- Next message: David Rubin: "Re: Iostream"
- Previous message: Victor Bazarov: "Re: Iostream"
- In reply to: ncstate: "Iostream"
- Next in thread: David Rubin: "Re: Iostream"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Thu, 23 Oct 2003 22:42:44 GMT
"ncstate" <member45487@dbforums.com> wrote in message
news:3517496.1066944307@dbforums.com...
>
> it seems when i try to compile this simple code I get an error message i
> believe is from g++ not finding the IOSTREAM header file.
No, it's telling you it cannot find the declaration of
an identifier you've used ('cout').
>i found the
> header file in /usr/include/c++/3.2.2/ so that is why it is included
> like that. suggestions?
Don't include it 'like that'.
> I'm running red hat 9
This doesn't matter. C++ is a platform independent language.
> code :
>
> #include </usr/include/c++/3.2.2/iostream>
Change to:
#include <iostream>
If this does not work, then your compiler is installed
and/or configured incorrectly.
Note that from the language's perspective <iostream> is a
standard *header* name, it does *not* signify a "file" name.
Many if not most implementations do provide an actual file
with the same or a similar name to implement a standard header,
but this is an implementation detail, not specified or
required by the language. E.g. a compiler could provide the
required declarations as 'hard coded' if it wanted and would
still be conforming -- the #include statement would still be
required however).
[Gratuitous whitespace removed from code below]
> int main()
> {
> cout << endl << endl << "Jeff" << endl;
> cout << "E115 Sec 010 B" << endl;
> cout << "Hello World" << endl << endl << endl;
>
> return 0;
> }
>
> errors:
>
> project2.C: In function `int main()':
>
> project2.C:6: `cout' undeclared (first use this function)
This is because 'cout' (and all standard library identifiers
except macros are declared in namespace 'std').
> project2.C:6: (Each undeclared identifier is reported only once for each
>
> function it appears
#include <iostream>
int main()
{
std::cout << "Hello world\n";
return 0;
}
or
#include <iostream>
using std::cout;
int main()
{
cout << "Hello world\n";
return 0;
}
or
#include <iostream>
using namespace std;
int main()
{
cout << "Hello world\n";
return 0;
}
(If desired, the scope of 'cout' can be further restricted
by putting the 'using' directive or declaration inside the
'main()' function.)
Note: while most implementations will work without it,
the declaration for 'endl' is provided by <ostream>.
It is allowed to be, but not required to be, provided by
<iostream>. 'endl' is also in namespace 'std'. (Its
'full name' is 'std::endl')
BTW, which C++ book(s) are you reading?
-Mike
- Next message: David Rubin: "Re: Iostream"
- Previous message: Victor Bazarov: "Re: Iostream"
- In reply to: ncstate: "Iostream"
- Next in thread: David Rubin: "Re: Iostream"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|