By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,260 Members | 1,362 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,260 IT Pros & Developers. It's quick & easy.

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

P: n/a
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.hheader for C++ includes, or <sstreaminstead of
the deprecated header <strstream.h>. To disable this warning use -Wno-
deprecated.
disk.cpp: In member function `bool Cdisk::open(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::open(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();
}

========

Feb 17 '07 #1
Share this Question
Share on Google+
4 Replies


P: n/a
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.hheader for C++ includes, or <sstreaminstead of
the deprecated header <strstream.h>. To disable this warning use -Wno-
deprecated.
disk.cpp: In member function `bool Cdisk::open(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
Feb 17 '07 #2

P: n/a
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)
Feb 18 '07 #3

P: n/a
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)
Feb 18 '07 #4

P: n/a
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
Feb 18 '07 #5

This discussion thread is closed

Replies have been disabled for this discussion.