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

U

uche

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();
}

========
 
J

John Harrison

uche said:
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
 
P

Pete Becker

uche said:
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)
 
L

Lionel B

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

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

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top