473,395 Members | 2,796 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

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

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
4 4974
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Dave Johnston | last post by:
Hi, I'm currently trying to create a wrapper that uses C functions but behaves like ifstream (from fstream.h) - this is because the platform I'm using (WinCE) doesn't support streams and this is...
6
by: Herv? LEBAIL | last post by:
Hi everybody, I'm writing a program which use the <string>, <vector> and <ifstream> classes. Given an array of string, i.e vector<string> file_names, example : file_names = "file1.txt"...
15
by: Christopher Benson-Manica | last post by:
The dumb-o-meter's pegging out today... What, if anything, is wrong with the following code? std::ifstream f( "myfile.txt" ); if( !f ) { cerr << "Couldn't open file\n"; } while( getline(f,s)...
8
by: ambar.shome | last post by:
Hi, We are working on Solaris SunOS 5.8. We are using ifstream of iostream namespace. The snippet is given below: #include <iostream.h> #include <fstream.h> boolean readFile() { char...
12
by: Steven T. Hatton | last post by:
I know of a least one person who believes std::ifstream::read() and std::ofstream::write() are "mistakes". They seem to do the job I want done. What's wrong with them. This is the code I...
1
by: tinks | last post by:
I am getting a linking error when I do something like this: ifstream dataFile; dataFile.open(dataFileName_, ios::in); while(dataFile) { dataFile.getline(buffer, MAX_DATA_FILE_LINE_LEN); //...
9
by: Notebooker | last post by:
Hello, I'm an intermediate noob reading-in data from ascii-file using an ifstream object. I have specified a c-style string buffer with size of type size_t and I am specifying to use this...
1
by: Xiaozhou.Yin | last post by:
Hi~ In the program,I first used the ifstream variable fin open the file and,open it again after called the fin.close().But the fin is fieled to open the file in the second time.The book I'm...
11
by: adramolek | last post by:
So... I'm trying to get used to using C++ ifstream (or ofstream) instead of stdio (although I'm having second thoughts). Anyways, I want to be able to display a meaningful error message if ifstream...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.