iostream.h not found

G

guddu

Hi,
I have installed g++ for windows from http://www.cmc.edu/math/alee/g++/g++.html
g++ is coorectly installed and path is set.
However looks like, path for standard header files is not set.
So when I use cout in the code, the code file gets compiled but it
gives the error as follows:

E:\Documents and Settings\VISHAL>g++ file.cpp
file.cpp: In function 'int main()':
file.cpp:7: error: 'cout' was not declared in this scope

if I #include<iostream.h>
I get following error :
E:\Documents and Settings\VISHAL>g++ file.cpp
file.cpp:3:21: error: iostream.h: No such file or directory
file.cpp: In function 'int main()':
file.cpp:7: error: 'cout' was not declared in this scope

Do I need to install standard file from some other location or some
other path needs to be set.

Thanks in advance,
vishal
 
A

Alf P. Steinbach

* guddu:
Hi,
I have installed g++ for windows from http://www.cmc.edu/math/alee/g++/g++.html
g++ is coorectly installed and path is set.
However looks like, path for standard header files is not set.
So when I use cout in the code, the code file gets compiled but it
gives the error as follows:

E:\Documents and Settings\VISHAL>g++ file.cpp
file.cpp: In function 'int main()':
file.cpp:7: error: 'cout' was not declared in this scope

if I #include<iostream.h>
I get following error :
E:\Documents and Settings\VISHAL>g++ file.cpp
file.cpp:3:21: error: iostream.h: No such file or directory
file.cpp: In function 'int main()':
file.cpp:7: error: 'cout' was not declared in this scope

Do I need to install standard file from some other location or some
other path needs to be set.

Thanks in advance,
vishal

Try this program:

<code>
#include <iostream>

int main()
{
using namespace std;
cout << "Hello, guddu!" << endl;
}
</code>


Cheers & hth.,

- Alf
 
G

guddu

Hi that worked. :)
My code was as follows :

<code>

#include<iostream>
int main()
{
using namespace std;
cout << "Hello guddu " << endl ;

return 0;

}


</code>

But I am wondering what magic was done by
[a] Replacing iostream.h with iostream
'using namespace std'

I assuned that specifying iostream.h would find declaration for cout.

Can you please quickly explain ?

Thanks and regards,
guddu
 
A

Alf P. Steinbach

* guddu:
Hi that worked. :)
My code was as follows :

<code>

#include<iostream>
int main()
{
using namespace std;
cout << "Hello guddu " << endl ;

return 0;

}


</code>

But I am wondering what magic was done by
[a] Replacing iostream.h with iostream
'using namespace std'

I assuned that specifying iostream.h would find declaration for cout.

Can you please quickly explain ?


[iostream.h] was the original iostreams library, before C++ was standardized.
With the standardization iostreams were templated on the character type, put in
namespace "std", and just to confuse editors with syntax coloring the suffix
[.h] was removed from all C++ specific standard library headers.

So, replacing [iostream.h] with [iostream] is replacing a pre-standard and
possibly not existing header, with the corresponding standard header.

And "using namespace std;" allows you to write e.g. "cout" instead of "std::cout".

By the way you don't need the "return 0;" since "main" is a very special
function -- among other special characteristics it has a default result, 0.

However, at least 50% of programmers prefer to use an explicit "return" anyway.


Cheers & hth.,

- Alf


PS: please don't top-post in this group; see the FAQ.
 
Ö

Öö Tiib

"using namespace std;" at file scope sucks for anything other than example
toy programs.  Explicitly using the std:: namespace qualifier actually
improves code comprehension IMO.

It is implementation detail and up to implementer of particular
compilation unit to decide, unless she puts it into headers or before
some #includes. I use using declarations and put these together with
everything compilation unit local into nameless namespace that stands
right after #includes. Mostly since i have tool that is doing it.

Imagine that it is not implemented but generated code with legacy
"iostream.h" time code generator then you have options:
1) make a script that replaces only #include "iostream.h" with
#include <iostream> and using namespace::std
2) make a script that replaces only #include "iostream.h" with
#include <iostream> and using declarations of std::cout, std::cin,
std::cerr, std::endl.
3) make a script that replaces #include "iostream.h" and all inctances
of cout, cin, cerr and endl with these std::crap.
4) rewrite that legacy code generator to produce standard compliant
code.

I go with 1) since its less work. When someone does 4) i would suggest
to generate result of 1) since she introduces less errors that way.
 
J

Juha Nieminen

Alf P. Steinbach said:
using namespace std;
cout << "Hello, guddu!" << endl;

You wrote a total of 25 characters in one line in order to save
writing 10 characters in the next line. Thus the total amount of
characters you saved was -15.

Seems kind of counterproductive.
 
A

Alf P. Steinbach

* Juha Nieminen:
You wrote a total of 25 characters in one line in order to save
writing 10 characters in the next line.

Can you think of any other purpose for the code than saving characters?


Cheers & hth.,

- Alf
 
J

Juha Nieminen

Alf P. Steinbach said:
* Juha Nieminen:

Can you think of any other purpose for the code than saving characters?

Not really. The 'using' statement seems completely useless and doesn't
add anything to the program, doesn't increase clarity or code quality,
or anything else I can think of. Seems like a complete waste of 15
additional characters.
 
K

Keith H Duggar

Yes, indeed. And you had no intention of putting Alf's comments in a bad
light by snipping context which you could just as easily have left in.
Funny thing how often such accidents happen in your messages.

Yeah, there really is no more appropriate word for that latest
Leigh action other than "moronic". Given he is a bit flustered
at the moment from the pwnage handed to him over in the switch
thread, but still ... his latest gives even morons a bad name.

Let the weasel/update/correct/clarify/change/justify/self-reply
hyperactive spam begin!

KHD
 
A

Alf P. Steinbach

* Juha Nieminen:
Not really. The 'using' statement seems completely useless and doesn't
add anything to the program, doesn't increase clarity or code quality,
or anything else I can think of. Seems like a complete waste of 15
additional characters.

Well, here's a hint: the purpose of the code was not to output "Hello, world".

:)


Cheers & hth.,

- ALf
 
T

tonydee

  You wrote a total of 25 characters in one line in order to save
writing 10 characters in the next line. Thus the total amount of
characters you saved was -15.

  Seems kind of counterproductive.

That's pretty unfair... Alf usefully showed Guddu how to get his
original code working, preserving the implicit namespaces he seemed to
want to use. Besides, once you correct the second line to "std::cout
<< "Hello, guddu!\n";", the "using..." only saves 5 ;-P.

Cheers,
Tony
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top