473,396 Members | 2,020 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Iostream


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. i found the
header file in /usr/include/c++/3.2.2/ so that is why it is included
like that. suggestions?

I'm running red hat 9

code :

#include </usr/include/c++/3.2.2/iostream>

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)

project2.C:6: (Each undeclared identifier is reported only once for each

function it appears
--
Posted via http://dbforums.com
Jul 19 '05 #1
13 3387
"ncstate" <me*********@dbforums.com> wrote in message
news:35****************@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. i found the
header file in /usr/include/c++/3.2.2/ so that is why it is included
like that. suggestions?

I'm running red hat 9

code :

#include </usr/include/c++/3.2.2/iostream>

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)

project2.C:6: (Each undeclared identifier is reported only once for each

function it appears


The 'cout' object is declared in the 'std' namespace. You should
either prefix it with "std::" or declare that you're using that
name:

using std::cout;
using std::endl; // as well

Get a decent book on C++.

Victor
Jul 19 '05 #2
"ncstate" <me*********@dbforums.com> wrote in message
news:35****************@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
Jul 19 '05 #3
ncstate wrote:
[snip - rearranged]
#include </usr/include/c++/3.2.2/iostream>
You can just #include <iostream>
int main()
{
cout << endl << endl << "Jeff" << endl; [snip] project2.C: In function `int main()':
project2.C:6: `cout' undeclared (first use this function)
project2.C:6: (Each undeclared identifier is reported only once for each
function it appears


Try std::cout and std::endl or 'using namespace std;' I found this
diagnostic a bit confusing too the first time I saw it.

/david

--
"As a scientist, Throckmorton knew that if he were ever to break wind in
the echo chamber, he would never hear the end of it."

Jul 19 '05 #4
> 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. i
found the header file in /usr/include/c++/3.2.2/ so that is why it is
included like that. suggestions?

I'm running red hat 9

#include </usr/include/c++/3.2.2/iostream>
I don't know about the requirements of the standard about that, but imho, if
your compiler forces you to specify such a path, it is broken. Ask in a
newsgroup supporting it

http://www.parashift.com/c++-faq-lit...t.html#faq-5.9
int main()
{

cout << endl << endl << "Jeff" << endl;
<snip>
errors:
project2.C: In function `int main()':

project2.C:6: `cout' undeclared (first use this function)


'cout' is defined in the std namespace (as all standard functions, classes
and objects are), so you must explictly refer to it :

std::cout << std::endl << "Jeff" << std::endl;

Or look up using directive and declaration.
Jonathan
Jul 19 '05 #5
"David Rubin" <fu******@warpmail.net> wrote in message
news:CO*******************@twister.nyc.rr.com...
project2.C: In function `int main()':
project2.C:6: `cout' undeclared (first use this function)
project2.C:6: (Each undeclared identifier is reported only once for each
function it appears
Try std::cout and std::endl or 'using namespace std;'


or:
using std::cout;
using std::endl;
I found this
diagnostic a bit confusing too the first time I saw it.


"'cout' undeclared." Exactly the case. How much more specific
could it be? :-)

Before you say e.g. "well the compiler should 'know' it's a
'namespace std' issue, I'll say that no, it cannot (and should not)
make such an assumption. I might want an identifer of my own named
e.g. 'cout', which I have every right to define, in either a 'global',
'file', 'namespace'*, or 'local' scope, and expect no problems until I
explicitly cause a conflict with a 'using' statement which brings
'std::cout' into scope.

(*) except namespace 'std', where the 'user' is not
allowed to define anything.
OP's problem is not an 'ambiguous' error message, but insufficient
background knowledge before using the compiler.

-Mike
Jul 19 '05 #6
ncstate wrote:

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. i found the
header file in /usr/include/c++/3.2.2/ so that is why it is included
like that. suggestions?

I'm running red hat 9

code :

#include </usr/include/c++/3.2.2/iostream>


It's been a little while, but I seem to recall that
including a file from the "builtin" include dirs is
done via:
#include <filename>
That tells the compiler to use its own include path(s).

But including a USER file is done via:
#include "filename"
That tells the compiler to use the include paths from
the compile commandline (or defaults)(or project/etc).

Try changing the < and > to " and " and see what
happens.

Mike
Jul 19 '05 #7

"MPBroida" <michael.p.broida@boeing_oops.com> wrote in message
news:3F9858AB.2DF20187@boeing_oops.com...
ncstate wrote:

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. i found the
header file in /usr/include/c++/3.2.2/ so that is why it is included
like that. suggestions?

I'm running red hat 9

code :

#include </usr/include/c++/3.2.2/iostream>


It's been a little while, but I seem to recall that
including a file from the "builtin" include dirs is
done via:
#include <filename>
That tells the compiler to use its own include path(s).

But including a USER file is done via:
#include "filename"
That tells the compiler to use the include paths from
the compile commandline (or defaults)(or project/etc).

Try changing the < and > to " and " and see what
happens.


Please check your facts before making such suggestions.

-Mike
Jul 19 '05 #8

Thanks for the help. the only thing that i seemed to find that worked
was to #include <iostream.h> and it gives me a depreciation message but
compiles and runs fine. is this normal for g++ 3.2.2?? it compiles fine
with #include <iostream> with g++ 2.8.1? should i just keep using the .h
extention and ignore the message?
--
Posted via http://dbforums.com
Jul 19 '05 #9
ncstate wrote:
Thanks for the help. the only thing that i seemed to find that worked
was to #include <iostream.h> and it gives me a depreciation message but
compiles and runs fine. is this normal for g++ 3.2.2?? it compiles fine
with #include <iostream> with g++ 2.8.1? should i just keep using the .h
extention and ignore the message?

No, you should use <iostream> -- which is the proper header -- and
correct your *code*.

HTH,
--ag
--
Artie Gold -- Austin, Texas
Oh, for the good old days of regular old SPAM.

Jul 19 '05 #10

"ncstate" <me*********@dbforums.com> wrote in message
news:35****************@dbforums.com...

Thanks for the help. the only thing that i seemed to find that worked
was to #include <iostream.h> and it gives me a depreciation message but
compiles and runs fine. is this normal for g++ 3.2.2?? it compiles fine
with #include <iostream> with g++ 2.8.1? should i just keep using the .h
extention and ignore the message?


No.

#include <iostream>

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

-Mike
Jul 19 '05 #11
Mike Wahler wrote:
[snip]
I found this
diagnostic a bit confusing too the first time I saw it.
"'cout' undeclared." Exactly the case. How much more specific
could it be? :-)

Before you say e.g. "well the compiler should 'know' it's a
'namespace std' issue, I'll say that no, it cannot (and should not)
make such an assumption.


I wasn't suggesting that.
OP's problem is not an 'ambiguous' error message, but insufficient
background knowledge before using the compiler.


This is more like it. After years of not using std::, I am sometimes
bewildered when the compiler can't find declarations I know
exist...somewhere.

/david

--
"As a scientist, Throckmorton knew that if he were ever to break wind in
the echo chamber, he would never hear the end of it."

Jul 19 '05 #12

Thanks for all the help.. Sorry I didn't catch on before. All of the
posts were helpful and appriciated.

Jeff
--
Posted via http://dbforums.com
Jul 19 '05 #13
Mike Wahler wrote:

"MPBroida" <michael.p.broida@boeing_oops.com> wrote in message
news:3F9858AB.2DF20187@boeing_oops.com...
ncstate wrote:

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. i found the
header file in /usr/include/c++/3.2.2/ so that is why it is included
like that. suggestions?

I'm running red hat 9

code :

#include </usr/include/c++/3.2.2/iostream>


It's been a little while, but I seem to recall that
including a file from the "builtin" include dirs is
done via:
#include <filename>
That tells the compiler to use its own include path(s).

But including a USER file is done via:
#include "filename"
That tells the compiler to use the include paths from
the compile commandline (or defaults)(or project/etc).

Try changing the < and > to " and " and see what
happens.


Please check your facts before making such suggestions.


Just looked in my "fact sack" and all looks
well. What facts are you unhappy with?

Mike
Jul 19 '05 #14

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: John Tiger | last post by:
Can anybody have idea about the difference between #include <iostream.h> and #include <iostream>. Is later one valid statement on any compiler. I tried compiling on MSVC second statement give...
19
by: ernst.stiegler | last post by:
Hello, I just want to read a whole line from a console input. What I don't understand is that I always have to press ENTER twice in order to see the line I've entered. Here's my code : ...
1
by: Pradyot Dhulipala | last post by:
Hi, I am using ns2.26 with the Makefile using C++ compiler version c++ (GCC) 3.2.2 (Mandrake Linux 9.1 3.2.2-3mdk). When I use iostream.h in a simple program and compile with c++ everything works...
2
by: humble04 | last post by:
Hi, I am compiling a collection of C++ code. Most of them are using the new format #include <iostream>. I think all of them because I failed at finding out which header file uses the old format ...
7
by: S. Nurbe | last post by:
Hi, probably this is a common problem but I couldn't find yet a proper solution (and I hope there is one). I have two relative complex frameworks: one uses only iostream.h the other one only...
1
by: Shane Ragone | last post by:
What happened to iostream.h in VS .NET? Are we now to code: #include <iostream> instead of: #include <iostream.h> All my past code that used iostream.h will no longer
1
by: Bill Sun | last post by:
Hi, I just want to using a console application in the .net enviroment. Before the main(), I using the #include "iostream.h" but the .net tell me:...
1
by: Ly Hoang Hai | last post by:
Hi all, I have just port my C++ 6.0 project into C++ project of Visual Studio.NET. However, .NET tell me that it can not find iostream.h. Some search on the internet tell me that I should change...
2
by: NewToCPP | last post by:
I am having some trouble including "iostream" "fstream" to my code. I tried the following ways and base times it did not work. What is the problem? test.cc: ======= ..... #include...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.