'ifstream' is used as a type, but is not defined as a type.

Discussion in 'C++' started by uche, Feb 17, 2007.

  1. uche

    uche Guest

    Hello, I am having a problem with my code in C++/C. I have struggled
    for a while and cannot find the solution to the problem...

    Here is the compiled..output:

    In file included from disk.cpp:8:
    disk.h:31:2: invalid preprocessing directive #inlcude
    In file included from disk.cpp:8:
    ****disk.h:89: error: 'ifstream' is used as a type, but is not defined
    as a type.*****
    In file included from /usr/include/c++/3.3/backward/iostream.h:31,
    from disk.cpp:11:
    /usr/include/c++/3.3/backward/backward_warning.h:32:2: warning:
    #warning This file includes at least one deprecated or antiquated
    header. Please consider using one of the 32 headers found in section
    17.4.1.2 of the C++ standard. Examples include substituting the <X>
    header for the <X.h> header for C++ includes, or <sstream> instead of
    the deprecated header <strstream.h>. To disable this warning use -Wno-
    deprecated.
    disk.cpp: In member function `bool Cdisk::eek:pen(const char*)':
    disk.cpp:16: error: `file_in' undeclared (first use this function)
    disk.cpp:16: error: (Each undeclared identifier is reported only once
    for each
    function it appears in.)

    ....sample code:
    ==================================================
    #ifndef DISK_H
    #define DISK_H

    #include <cstdlib>
    #include <iomanip>
    #include <iostream>
    #inlcude <fstream>

    class Cdisk
    {
    public:
    bool open(const char* filename);
    bool eof() const;
    int read(char* buffer, int length); // get_byte
    bool seek(int position);
    int tell() const;
    void close();
    ifstream file_in;
    };
    ==================================================
    //disk.cpp
    #include "disk.h"
    #include <cstdlib>
    #include <iomanip>
    #include <iostream.h>
    #include <fstream>

    bool Cdisk::eek:pen(const char* filename)
    {
    file_in.open(filename, ios::binary);
    if (!file_in)
    {
    printf("Fail to Open\n");
    return false;
    }
    return true;

    }

    bool Cdisk::eof() const
    {
    if (file_in.eof())
    return 1;
    return 0;
    }

    int Cdisk::read(char* buffer, int length)
    {
    file_in.read(buffer,length);
    return file_in.gcount();
    }

    bool Cdisk::seek(int position)
    {
    long pos;
    long file_beg, file_end;
    long file_size;
    pos = fseek(file_in, position, 0);
    if (pos == 0 || pos <= 511)
    return true;
    return false;
    }

    int Cdisk::tell() const
    {

    return file_in.tellg();
    }

    void Cdisk::close()
    {
    file_in.close();
    }

    ========
    uche, Feb 17, 2007
    #1
    1. Advertising

  2. uche wrote:
    > Hello, I am having a problem with my code in C++/C. I have struggled
    > for a while and cannot find the solution to the problem...
    >


    Corrections below

    > Here is the compiled..output:
    >
    > In file included from disk.cpp:8:
    > disk.h:31:2: invalid preprocessing directive #inlcude
    > In file included from disk.cpp:8:
    > ****disk.h:89: error: 'ifstream' is used as a type, but is not defined
    > as a type.*****
    > In file included from /usr/include/c++/3.3/backward/iostream.h:31,
    > from disk.cpp:11:
    > /usr/include/c++/3.3/backward/backward_warning.h:32:2: warning:
    > #warning This file includes at least one deprecated or antiquated
    > header. Please consider using one of the 32 headers found in section
    > 17.4.1.2 of the C++ standard. Examples include substituting the <X>
    > header for the <X.h> header for C++ includes, or <sstream> instead of
    > the deprecated header <strstream.h>. To disable this warning use -Wno-
    > deprecated.
    > disk.cpp: In member function `bool Cdisk::eek:pen(const char*)':
    > disk.cpp:16: error: `file_in' undeclared (first use this function)
    > disk.cpp:16: error: (Each undeclared identifier is reported only once
    > for each
    > function it appears in.)
    >
    > ...sample code:
    > ==================================================
    > #ifndef DISK_H
    > #define DISK_H
    >
    > #include <cstdlib>
    > #include <iomanip>
    > #include <iostream>
    > #inlcude <fstream>
    >
    > class Cdisk
    > {
    > public:
    > bool open(const char* filename);
    > bool eof() const;
    > int read(char* buffer, int length); // get_byte
    > bool seek(int position);
    > int tell() const;
    > void close();
    > ifstream file_in;


    std::ifstream file_in;

    ifstream is in the std namespace.


    > };
    > ==================================================
    > //disk.cpp
    > #include "disk.h"
    > #include <cstdlib>
    > #include <iomanip>
    > #include <iostream.h>


    #include <iostream>

    The error message said, 'dont use <X.h>', so don't.

    john
    John Harrison, Feb 17, 2007
    #2
    1. Advertising

  3. uche

    Pete Becker Guest

    uche wrote:
    > Hello, I am having a problem with my code in C++/C. I have struggled
    > for a while and cannot find the solution to the problem...
    >
    > Here is the compiled..output:
    >
    > In file included from disk.cpp:8:
    > disk.h:31:2: invalid preprocessing directive #inlcude


    Read the error message from beginning to end. If you don't understand
    it, read it again.

    --

    -- Pete
    Roundhouse Consulting, Ltd. (www.versatilecoding.com)
    Author of "The Standard C++ Library Extensions: a Tutorial and
    Reference." (www.petebecker.com/tr1book)
    Pete Becker, Feb 18, 2007
    #3
  4. uche

    Pete Becker Guest

    John Harrison wrote:
    >
    > The error message said, 'dont use <X.h>', so don't.
    >


    That wasn't an error message, it was a warning. And it almost certainly
    has nothing to do with the problem, since it came after the error message.

    --

    -- Pete
    Roundhouse Consulting, Ltd. (www.versatilecoding.com)
    Author of "The Standard C++ Library Extensions: a Tutorial and
    Reference." (www.petebecker.com/tr1book)
    Pete Becker, Feb 18, 2007
    #4
  5. uche

    Lionel B Guest

    On Sat, 17 Feb 2007 15:24:52 -0800, uche wrote:

    > Hello, I am having a problem with my code in C++/C.


    Which is it then? (ok, it's C++).

    > I have struggled
    > for a while and cannot find the solution to the problem...
    >
    > Here is the compiled..output:
    >
    > In file included from disk.cpp:8:
    > disk.h:31:2: invalid preprocessing directive #inlcude


    #inlcude ???

    [snip]

    > #inlcude <fstream>


    #inlcude ???

    [snip]

    I know my eyes frequently glaze over staring at compiler error messages,
    but it's surprising how often they really are telling you what the problem
    is...

    --
    Lionel B
    Lionel B, Feb 18, 2007
    #5
    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. Kabeer
    Replies:
    6
    Views:
    3,219
    Thomas Matthews
    Aug 21, 2003
  2. William Payne

    Warning: Defined but not used

    William Payne, Feb 20, 2004, in forum: C++
    Replies:
    3
    Views:
    15,305
    William Payne
    Feb 20, 2004
  3. Eric Lilja
    Replies:
    3
    Views:
    1,070
    scott urban
    Jan 30, 2005
  4. Oodini
    Replies:
    1
    Views:
    1,766
    Keith Thompson
    Sep 27, 2005
  5. Travis
    Replies:
    6
    Views:
    542
    Markus Schoder
    Jun 28, 2007
Loading...

Share This Page