473,767 Members | 2,284 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

'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..outpu t:

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_warnin g.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 <sstreaminste ad of
the deprecated header <strstream.h> . To disable this warning use -Wno-
deprecated.
disk.cpp: In member function `bool Cdisk::open(con st 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(con st char* filename)
{
file_in.open(fi lename, 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(cha r* buffer, int length)
{
file_in.read(bu ffer,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 4998
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..outpu t:

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_warnin g.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 <sstreaminste ad of
the deprecated header <strstream.h> . To disable this warning use -Wno-
deprecated.
disk.cpp: In member function `bool Cdisk::open(con st 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..outpu t:

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..outpu t:

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
13779
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 the easiest way to take a huge project across onto it. Basically, I've hit a problem. I have no idea how the ifstream class handles directories. In the code I have (which I didn't write), there are several places whereby an ifstream stream is...
6
3660
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" file_names = "file2.txt" etc ...
15
2840
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) ) { cout << s << '\n'; }
8
3387
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 readStr;
12
11665
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 currently have as a test for using std::ifstream::read(). Is there anything wrong with the way I'm getting the file? #include <vector> #include <iomanip> #include <fstream> #include <iostream>
1
2886
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); // This line creates linking issue on solaris }
9
8800
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 buffer size as the number of characters to read in using the function read(). The issue I am having is read() expects that the value for the number of characters to read-in will be of type std::streamsize, which is apparently signed int. My buffer
1
4912
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 learning hadn't picked out this.Is it a common problem?Or just occurs in Vc++6.0? #include<fstream> #include<iostream> using namespace std; int count(ifstream& fin);
11
8145
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 fails to open a file, but nothing I read about ifstream says anything about a reliable place to get an error message. Using stdio I can simply do: FILE *f = fopen(filename, "rb"); if (!f) perror(filename);
0
9404
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10168
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10009
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9838
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7381
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6651
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5279
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3929
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2806
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.