c++的template clsaa的问题:源程序有什么错误?清指示!

lanchat 2002-04-22 09:30:32
//file *.h
#ifndef CFileT_H
#define CFileT_H
#include <iostream>
#include <fstream>
#include "conio.h"
using std::cout;
using std::cin;
using std::endl;
const int FILENAMEMAXLEN =20;
template< class DATA_T
class CFileT
{public:
CFileT(char * = "Mydata.dat");
bool InitRead( void );
bool InitWrite( void
void CloseRead();
void CloseWrite();
void WriteData( const DATA_T out_data
void ReadData( DATA_T &in_data );
int GetStatus();
~CFileT();
private://private member data
char Filename[ FILENAMEMAXLEN ];
// ifstream InFile; //这二行如果不注释掉,会有missing storage-class or //type specifiers错误提示,为什么?
// ofstream OutFile; //
int Status;
};
#endif
//file *.cpp
//member function definitions for CFileX class

#include<iostream>
using std::cout;
using std::cin;
using std::endl;
using std::ios;
using std::cerr;

#include "CFileT.h"

template< class DATA_T >
CFileT<DATA_T>::CFileT(char* filename)
{
strcpy(Filename, filename);
}
template< class DATA_T >
bool CFileT<DATA_T>::InitRead(void)
{ InFile.open(Filename,ios::in);
if (!InFile)
{cout<<"\n The File Could Not Be Opened.\n\n";
return 0;
}
else return 1;
}

template< class DATA_T >
void CFileT<DATA_T>::CloseRead()
{
if(InFile)
{InFile.close();
}
}
template< class DATA_T >
void CFileT<DATA_T>::ReadData(DATA_T &in_data)
{

if(this->GetStatus())InFile>>in_data
}
template< class DATA_T >
int CFileT<DATA_T>::GetStatus()
{if(!InFile.eof()) Status=1;
else Status=0;
return Status;
}
template< class DATA_T >
bool CFileT<DATA_T>::InitWrite()
{
OutFile.open(Filename,ios::out);
if (!OutFile)
{cout<<"The File Could Not Be Opened.\n";
return 0;
}
else return 1;
}
template< class DATA_T >
void CFileT<DATA_T>::CloseWrite()
{ if(OutFile)
OutFile.close();
}

template< class DATA_T >
void CFileT<DATA_T>::WriteData(const DATA_T out_data)

{
OutFile <<out_data<<"\n";
}

template< class DATA_T >
CFileT<DATA_T>::~CFileT()
{
CloseRead();
CloseWrite();
}
//test.cpp
//this is a test of function for class cfilex as below:
///////////////////////////////////////////////////////
#include <iostream>
#include "CQueue.h"
#include "CFilet.h"
#include "conio.h"
using std::cout;
using std::cin;
using std::endl;
void run_app( void );

void main()
{ run_app();
cout << "finished ";
}

void run_app( void )
{ CFileT <int> myfile;CFileT <int> myfile1;
int trp;
if(!(myfile.InitWrite()))exit(0);
trp=-1;
cout << "Please type the first group data of variable as time,rotation and pulse:\n" ;
cin>>trp;
cout << "Now save the first group data in disk file.\n" ;
myfile.WriteData(trp);
trp=-1L;
cout << "Please type the second group data of variable as time,rotation and pulse:\n" ;
cin>>trp;
cout << "Now save the second group data in disk file.\n" ;
myfile.WriteData(trp);
myfile.CloseWrite();
getch();

cout << "Now read these datas from disk file,and display them as below:\n" ;
trp=-1;
if(!(myfile.InitRead()))exit(0);
while(myfile.GetStatus())
{
myfile.ReadData(trp);
if(myfile.GetStatus())
cout<<trp<<"\n";
}
myfile.CloseRead();

CQueue intQueuex,intQueue1;
int popInteger, i;
cout << "processing the integer list and save it to disk file:\n" << endl;

for ( i = 0; i < 6; i++ ) {
intQueue1.InsertData( i );
}
intQueue1.PrintData();
getch();

if(!(myfile.InitWrite()))exit(0);
trp=-1L;
while ( !intQueue1.isEmpty() )
{
intQueue1.RemoveData( popInteger );
cout << popInteger << " remove from list1.\n" ;
trp=popInteger;
intQueue1.PrintData();
myfile.WriteData(trp);
}

myfile.CloseWrite();

getch();
cout << "Now read these datas from disk file,and display them as below:\n" ;
trp=-1;
if(!(myfile1.InitRead()))exit(0);
while(myfile1.GetStatus())
{
myfile1.ReadData(trp);
if(myfile1.GetStatus())
{
intQueuex.InsertData(trp);
}
}
myfile1.CloseRead();
intQueuex.PrintData();
}
上面程序有什么错误?清指示!//cqueue是类,限于篇幅,就不粘贴了
...全文
125 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
tonyblues 2002-04-23
  • 打赏
  • 举报
回复
#include <fstream.h>
huangwu007 2002-04-23
  • 打赏
  • 举报
回复
#include <iostream>
#include <fstream>

都没有加.h
neptunez 2002-04-23
  • 打赏
  • 举报
回复
namespace std? should be
zosatapo 2002-04-23
  • 打赏
  • 举报
回复
#include <fstream>
中定义是放在namespace std中的,但是你在引用的使用没有
提供确切的namespace,但是你又没有在程序其他地方定义这个类,
所以出现找不到类定义的提示。
Asus 2002-04-23
  • 打赏
  • 举报
回复
你那么的using std:cout之类的句子用一行using namespace std;就可以替代了
fangrk 2002-04-23
  • 打赏
  • 举报
回复
增加using namespace std;

70,037

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧