iostream.h not found

Discussion in 'C++' started by guddu, Apr 18, 2010.

  1. guddu

    guddu Guest

    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
    guddu, Apr 18, 2010
    #1
    1. Advertising

  2. * 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
    Alf P. Steinbach, Apr 18, 2010
    #2
    1. Advertising

  3. guddu

    guddu Guest

    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


    On Apr 18, 3:36 pm, "Alf P. Steinbach" <> wrote:
    > * guddu:
    >
    >
    >
    > > Hi,
    > > I have installed g++ for windows fromhttp://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
    guddu, Apr 18, 2010
    #3
  4. * 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.
    Alf P. Steinbach, Apr 18, 2010
    #4
  5. guddu

    Öö Tiib Guest

    On 18 apr, 14:11, "Leigh Johnston" <> wrote:
    > "Alf P. Steinbach" <> wrote in messagenews:hqep7e$sgo$-september.org...
    >
    > > And "using namespace std;" allows you to write e.g. "cout" instead of
    > > "std::cout".

    >
    > "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.
    Öö Tiib, Apr 18, 2010
    #5
  6. Alf P. Steinbach <> wrote:
    > 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.
    Juha Nieminen, Apr 19, 2010
    #6
  7. * Juha Nieminen:
    > Alf P. Steinbach <> wrote:
    >> 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.


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


    Cheers & hth.,

    - Alf
    Alf P. Steinbach, Apr 19, 2010
    #7
  8. Alf P. Steinbach <> wrote:
    > * Juha Nieminen:
    >> Alf P. Steinbach <> wrote:
    >>> 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.

    >
    > 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.
    Juha Nieminen, Apr 20, 2010
    #8
  9. On Apr 18, 7:58 am, Pete Becker <> wrote:
    > Leigh Johnston wrote:
    >
    > > "Pete Becker" <> wrote in message
    > >news:...
    > >> Leigh Johnston wrote:
    > >>> "Alf P. Steinbach" <> wrote in message
    > >>>news:hqep7e$sgo$-september.org...
    > >>>> And "using namespace std;" allows you to write e.g. "cout" instead
    > >>>> of "std::cout".

    >
    > >>> "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.

    >
    > >> And, oddly enough, the part of Alf's message that was snipped showed
    > >> code used "using namespace std" in function scope, not file scope.
    > >> Funny thing how relevant context keeps disappearing.

    >
    > > It was simply giving advice relating to "using namespace std;" that a
    > > reader may not be aware of, context is irrelevant, I was simply making
    > > an additional point.

    >
    > 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
    Keith H Duggar, Apr 20, 2010
    #9
  10. * Juha Nieminen:
    > Alf P. Steinbach <> wrote:
    >> * Juha Nieminen:
    >>> Alf P. Steinbach <> wrote:
    >>>> 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.

    >> 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.


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

    :)


    Cheers & hth.,

    - ALf
    Alf P. Steinbach, Apr 20, 2010
    #10
  11. guddu

    tonydee Guest

    On Apr 19, 9:06 pm, Juha Nieminen <> wrote:
    > Alf P. Steinbach <> wrote:
    >
    > >     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.


    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
    tonydee, Apr 21, 2010
    #11
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. William Parker
    Replies:
    1
    Views:
    3,085
    Martin
    Jun 27, 2004
  2. John Tiger
    Replies:
    10
    Views:
    5,584
  3. ai@work
    Replies:
    9
    Views:
    540
    Ron Natalie
    Dec 16, 2004
  4. S. Nurbe

    iostream + iostream.h

    S. Nurbe, Jan 14, 2005, in forum: C++
    Replies:
    7
    Views:
    770
    red floyd
    Jan 15, 2005
  5. red floyd
    Replies:
    3
    Views:
    534
    Dietmar Kuehl
    Mar 8, 2005
Loading...

Share This Page