fstream error on SUN

Discussion in 'C++' started by ratzeel, Nov 8, 2005.

  1. ratzeel

    ratzeel Guest

    The following snippet code throws an error while compiling on SUN os..

    Any idea how to resolve this...

    #include <iostream.h>
    #include <fstream.h>
    #include <math.h>
    #include <algorithm>
    using namespace std;

    ..........
    ..........

    fstream fp;
    fp.open((*it).c_str(),ios::in); // Line 223
    .......
    .......
    fp.open((*it).c_str(),ios::in); // Line 345


    The error is as follows:

    line 223: Error: The name fstream is ambiguous, fstream and
    std::fstream.
    line 345: Error: The name ios is ambiguous, ios and std::ios.

    TIA, ratzeel
     
    ratzeel, Nov 8, 2005
    #1
    1. Advertising

  2. ratzeel

    Guest

    ratzeel wrote:
    > The following snippet code throws an error while compiling on SUN os..
    >
    > Any idea how to resolve this...
    >
    > #include <iostream.h>


    Not a standard C++ header

    > #include <fstream.h>


    Not a standard C++ header

    > #include <math.h>
    > #include <algorithm>


    These two are OK

    > using namespace std;
    >
    > .........
    > .........
    >
    > fstream fp;
    > fp.open((*it).c_str(),ios::in); // Line 223
    > ......
    > ......
    > fp.open((*it).c_str(),ios::in); // Line 345
    >
    >
    > The error is as follows:
    >
    > line 223: Error: The name fstream is ambiguous, fstream and
    > std::fstream.
    > line 345: Error: The name ios is ambiguous, ios and std::ios.
    >
    > TIA, ratzeel


    http://www.parashift.com/c -faq-lite/coding-standards.html#faq-27.4

    Gavin Deane
     
    , Nov 8, 2005
    #2
    1. Advertising

  3. ratzeel

    ratzeel Guest

    Thanks. The problem gone away by removing the using namespace std line.
     
    ratzeel, Nov 9, 2005
    #3
  4. ratzeel

    Guest

    ratzeel wrote:
    > Thanks. The problem gone away by removing the using namespace std line.


    A summary of your problem is:

    #include <iostream.h>
    #include <fstream.h>

    using namespace std;

    <some code using the names fstream and ios>

    line 223: Error: The name fstream is ambiguous, fstream and
    std::fstream.
    line 345: Error: The name ios is ambiguous, ios and std::ios.

    Do you understand why removing
    using namespace std;
    makes the problem go away?
    http://www.parashift.com/c -faq-lite/coding-standards.html#faq-27.5

    You could equally well make the problem go away by including the
    standard <iostream> and <fstream> headers instead of <iostream.h> and
    <fstream.h>, as the FAQ I first pointed to suggests.
    http://www.parashift.com/c -faq-lite/coding-standards.html#faq-27.4

    Your headers ending in .h are non-standard, which means that the next
    compiler you use may or may not provide tham at all, and even if it
    does, the contents may or may not be the same as what you are used to
    using.

    On the other hand, if you learn how to use the standard headers, you
    will get identical functionality available on every conforming C++
    compiler.

    If you understand all that and you are happy with the non-standard .h
    headers then that's fine. But bear in mind that this group discusses
    standard C++ so you won't be able to get help here with code that
    relies on your particular implementation of <iostream.h>

    Gavin Deane
     
    , Nov 9, 2005
    #4
    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. James Cham
    Replies:
    0
    Views:
    379
    James Cham
    Jul 21, 2003
  2. Roy Benjamin
    Replies:
    3
    Views:
    556
    Mike Schilling
    Jul 23, 2003
  3. Joan MacEachern
    Replies:
    0
    Views:
    344
    Joan MacEachern
    Oct 1, 2003
  4. Replies:
    0
    Views:
    2,913
  5. Armando
    Replies:
    6
    Views:
    772
    Armando
    Jan 29, 2004
Loading...

Share This Page