Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > 'ifstream' is used as a type, but is not defined as a type.

Reply
Thread Tools

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

 
 
uche
Guest
Posts: n/a
 
      02-17-2007
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: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: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();
}

========

 
Reply With Quote
 
 
 
 
John Harrison
Guest
Posts: n/a
 
      02-17-2007
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: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
 
Reply With Quote
 
 
 
 
Pete Becker
Guest
Posts: n/a
 
      02-18-2007
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)
 
Reply With Quote
 
Pete Becker
Guest
Posts: n/a
 
      02-18-2007
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)
 
Reply With Quote
 
Lionel B
Guest
Posts: n/a
 
      02-18-2007
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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Defined but not used? But I am using it! Travis C++ 6 06-28-2007 08:23 PM
#if (defined(__STDC__) && !defined(NO_PROTOTYPE)) || defined(__cplusplus) Oodini C Programming 1 09-27-2005 07:58 PM
Warning about defined but not used for global variable Eric Lilja C++ 3 01-30-2005 05:22 PM
Warning: Defined but not used William Payne C++ 3 02-20-2004 08:45 PM
'NODE' is used as a type, but has not been defined as a type Kabeer C++ 6 08-21-2003 03:54 PM



Advertisments