找到了意外的文件结尾,这是我弄错了什么. [英] Unexpected end of file found, what I make it wrong.
问题描述
我将发布代码和错误,谢谢您的帮助.
在main.cpp中:
I''ll post the code and the errors, thank you for helping me.
In main.cpp:
// 6Stack.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <iostream.h>
#include "SeqStack.h"
#define maxsize_seq 50
#define end_tail 10000
int main(int argc, char* argv[])
{
// printf("Hello World!\n");
SeqStack<int> SeqStack1(maxsize_seq);
int Push_Numbers_Int, Pop_Size, Pop_Number, Stack_Size;
cout<<"Push the Stack! Stopped by 10000!"<<endl;
while (1)
{
cin>>Push_Numbers_Int;
if (Push_Numbers_Int!=end_tail)
{
SeqStack1.Push(Push_Numbers_Int);
}
else
break;
}
cout<<"Pop the Stack! Input the number of Poping out!"<<endl;
cin>>Pop_Size;
for (int i=0;i<Pop_Size;i++)
{
if (SeqStack1.Pop(Pop_Number))
{
cout<<Pop_Number<<endl;
}
else
break;
}
cout<<"Head of the Stack:"<<endl;
if (SeqStack1.Get_Top(Pop_Number))
{
cout<<Pop_Number<<endl;
}
else
cout<<"Error!"<<endl;
cout<<"The size of the Stack is:"<<endl;
Stack_Size=SeqStack1.Get_Size();
cout<<Stack_Size;
return 0;
}
在SeqStack.cpp中:
In SeqStack.cpp:
<pre lang="vb">// SeqStack.cpp: implementation of the SeqStack class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "SeqStack.h"
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
在Stack.cpp中:
In Stack.cpp:
<pre lang="vb">// Stack.cpp: implementation of the Stack class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "Stack.h"
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
在SeqStack.h
In SeqStack.h
<pre lang="xml">// SeqStack.h: interface for the SeqStack class.
//
//////////////////////////////////////////////////////////////////////
#if !defined(AFX_SEQSTACK_H__94EF3A76_EB42_4B3D_BE22_1B9F8E253D2D__INCLUDED_)
#define AFX_SEQSTACK_H__94EF3A76_EB42_4B3D_BE22_1B9F8E253D2D__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#include <assert.h>
#include "Stack.h"
#define Stackincreament 20;
template<class T>
class SeqStack : public Stack<T>
{
public:
SeqStack(int len);
void Push(const T &x);
bool Pop(T &x);
bool Get_Top(T &x);
bool Is_Empty();
bool Is_Full();
int Get_Size();
virtual ~SeqStack();
private:
T *elements;
int top;
int maxsize;
void Overflow_Process();
};
template<class T>
class SeqStack<T>::SeqStack(int len)
{
top=-1;
maxsize=len;
T *elements=new T[maxsize];
assert(elements!=null);
}
template<class T>
void class SeqStack<>::Overflow_Process()
{
T *NewArray=new T[maxsize+Stackincreament];
if (NewArray==NULL)
{
cout<<"Error!!!"<<endl;
exit(1);
}
maxsize=maxsize+Stackincreament;
delete []elements;
elements=NewArray;
}
template<class T>
void class SeqStack<T>::Push(const T &x)
{
if (Is_Full()==true)
{
Overflow_Process();
}
elements[++top]=x;
}
template<class T>
bool class SeqStack<T>::Pop(T &x)
{
if (Is_Empty()==true)
{
return false;
}
x=elements[top--];
return true;
}
template<class T>
bool class SeqStack<T>::Get_Top(T &x)
{
if (Is_Empty()==true)
{
cerr<<"Error!!!"<<endl;
return false;
}
x=elements[top];
return true;
}
template<class T>
int class SeqStack<T>::Get_Size()
{
int Size_SeqStack;
Size_SeqStack=top+1;
return Size_SeqStack;
}
template<class T>
bool class SeqStack<T>::Is_Full()
{
if (top==maxsize-1)
{
return true;
}
else
return false;
}
template<class T>
bool class SeqStack<T>::Is_Empty()
{
if (top!=maxsize-1)
{
return true;
}
else
return false;
}
template<class T>
class SeqStack<T>::~SeqStack()
{
delete []elements;
}
#endif // !defined(AFX_SEQSTACK_H__94EF3A76_EB42_4B3D_BE22_1B9F8E253D2D__INCLUDED_)
在Stack.h
In Stack.h
// Stack.h: interface for the Stack class.
//
//////////////////////////////////////////////////////////////////////
#if !defined(AFX_STACK_H__A023084D_646A_4916_BC79_6C1E85CD4940__INCLUDED_)
#define AFX_STACK_H__A023084D_646A_4916_BC79_6C1E85CD4940__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
template<class T>
class Stack
{
public:
Stack();
// pure virtual functions, cannot be used if not implemented in derived classes,
// must be implemented in derived classes
virtual void Push(const T &x)=0;
virtual bool Pop(T &x)=0;
// constant methods: cannot modify data members of this class:
virtual bool Get_Top(T &x) const=0;
virtual bool Is_Empty() const=0;
virtual bool Is_Full() const=0;
virtual int Get_Size() const=0;
virtual ~Stack();
};
#endif // !defined(AFX_STACK_H__A023084D_646A_4916_BC79_6C1E85CD4940__INCLUDED_)
错误:
--------------------配置:6Stack-Win32调试--------------------
正在编译...
6Stack.cpp
C:\ Allfiles \ Tony \ Learning \ Data_Structure \ small_program \ data_structure_operation \ 6Stack \ 6stack.cpp(56):致命错误C1004:发现文件意外结束
SeqStack.cpp
C:\ Allfiles \ Tony \ Learning \ Data_Structure \ small_program \ data_structure_operation \ 6Stack \ SeqStack.cpp(12):致命错误C1004:意外发现文件结尾
正在生成代码...
执行cl.exe时出错.
6Stack.exe-2个错误,0个警告
Error:
--------------------Configuration: 6Stack - Win32 Debug--------------------
Compiling...
6Stack.cpp
C:\Allfiles\Tony\Learning\Data_Structure\small_program\data_structure_operation\6Stack\6stack.cpp(56) : fatal error C1004: unexpected end of file found
SeqStack.cpp
C:\Allfiles\Tony\Learning\Data_Structure\small_program\data_structure_operation\6Stack\SeqStack.cpp(12) : fatal error C1004: unexpected end of file found
Generating Code...
Error executing cl.exe.
6Stack.exe - 2 error(s), 0 warning(s)
推荐答案
在SeqStack.h和Stack.h
include "stdafx.h" in SeqStack.h and Stack.h
中包括"stdafx.h"
您的代码中有很多错误:
1-将
There A LOT of errors in your code:
1- change
#include <iostream.h>
更改为
#include <iostream>
2-在主cpp文件中,在包含之后添加
2- in the main cpp file, after the includes, add
using namespace std;
3-将null
更改为NULL
4-从Stack
类中删除构造函数和析构函数
5-在Overflow_Process
方法的实现中,缺少<T>
6-从每个方法实现中删除class
关键字
7-在SeqStack
声明中添加virtual
和const
关键字以匹配
Stack
类原型.
8-将const
添加到SeqStack
方法实现中以匹配先前的声明
9-将
3- change null
into NULL
4- remove the constructor and destructor from the Stack
class
5- in the implementation of Overflow_Process
method, a <T>
is missing
6- remove the class
keyword from every method implementation
7- add virtual
and const
keywords in the SeqStack
declaration to match
the Stack
class prototypes.
8- add the const
to the SeqStack
methods implementation to match the previous declarations
9- change
#define Stackincreament 20;
更改为
#define Stackincreament 20
完成所有这些更改后,应进行编译. :)
After doing all these changes, it should compile. :)
这里是完整的更正代码:
stdafx.h
Here is the complete corrected code:
stdafx.h
// stdafx.h : include file for standard system include files,
// or project specific include files that are used frequently, but
// are changed infrequently
//
#pragma once
#include "targetver.h"
#include <stdio.h>
#include <tchar.h>
// TODO: reference additional headers your program requires here
main.cpp
main.cpp
// 6Stack.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <iostream>
#include "SeqStack.h"
#define maxsize_seq 50
#define end_tail 10000
using namespace std;
int main(int argc, char* argv[])
{
// printf("Hello World!\n");
SeqStack<int> SeqStack1(maxsize_seq);
int Push_Numbers_Int, Pop_Size, Pop_Number, Stack_Size;
cout<<"Push the Stack! Stopped by 10000!"<<endl;
while (1)
{
cin>>Push_Numbers_Int;
if (Push_Numbers_Int!=end_tail)
{
SeqStack1.Push(Push_Numbers_Int);
}
else
break;
}
cout<<"Pop the Stack! Input the number of Poping out!"<<endl;
cin>>Pop_Size;
for (int i=0;i<Pop_Size;i++)
{
if (SeqStack1.Pop(Pop_Number))
{
cout<<Pop_Number<<endl;
}
else
break;
}
cout<<"Head of the Stack:"<<endl;
if (SeqStack1.Get_Top(Pop_Number))
{
cout<<Pop_Number<<endl;
}
else
cout<<"Error!"<<endl;
cout<<"The size of the Stack is:"<<endl;
Stack_Size=SeqStack1.Get_Size();
cout<<Stack_Size;
return 0;
}
Stack.h
Stack.h
// Stack.h: interface for the Stack class.
//
//////////////////////////////////////////////////////////////////////
#if !defined(AFX_STACK_H__A023084D_646A_4916_BC79_6C1E85CD4940__INCLUDED_)
#define AFX_STACK_H__A023084D_646A_4916_BC79_6C1E85CD4940__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
template<class T>
class Stack
{
public:
// pure virtual functions, cannot be used if not implemented in derived classes,
// must be implemented in derived classes
virtual void Push(const T &x)=0;
virtual bool Pop(T &x)=0;
// constant methods: cannot modify data members of this class:
virtual bool Get_Top(T &x) const=0;
virtual bool Is_Empty() const=0;
virtual bool Is_Full() const=0;
virtual int Get_Size() const=0;
};
#endif // !defined(AFX_STACK_H__A023084D_646A_4916_BC79_6C1E85CD4940__INCLUDED_)
Stack.cpp
Stack.cpp
// Stack.cpp: implementation of the Stack class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "Stack.h"
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
SeqStack.h
SeqStack.h
// SeqStack.h: interface for the SeqStack class.
//
//////////////////////////////////////////////////////////////////////
#if !defined(AFX_SEQSTACK_H__94EF3A76_EB42_4B3D_BE22_1B9F8E253D2D__INCLUDED_)
#define AFX_SEQSTACK_H__94EF3A76_EB42_4B3D_BE22_1B9F8E253D2D__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#include <assert.h>
#include "Stack.h"
#define Stackincreament 20
template<class T>
class SeqStack : public Stack<T>
{
public:
SeqStack(int len);
virtual void Push(const T &x);
virtual bool Pop(T &x);
virtual bool Get_Top(T &x) const;
virtual bool Is_Empty() const;
virtual bool Is_Full() const;
virtual int Get_Size() const;
virtual ~SeqStack();
private:
T *elements;
int top;
int maxsize;
void Overflow_Process();
};
template<class T>
SeqStack<T>::SeqStack(int len)
{
top=-1;
maxsize=len;
T *elements=new T[maxsize];
assert(elements!=NULL);
}
template<class T>
void SeqStack<T>::Overflow_Process()
{
T *NewArray=new T[maxsize+Stackincreament];
if (NewArray==NULL)
{
cout<<"Error!!!"<<endl;
exit(1);
}
maxsize=maxsize+Stackincreament;
delete []elements;
elements=NewArray;
}
template<class T>
void SeqStack<T>::Push(const T &x)
{
if (Is_Full()==true)
{
Overflow_Process();
}
elements[++top]=x;
}
template<class T>
bool SeqStack<T>::Pop(T &x)
{
if (Is_Empty()==true)
{
return false;
}
x=elements[top--];
return true;
}
template<class T>
bool SeqStack<T>::Get_Top(T &x) const
{
if (Is_Empty()==true)
{
cerr<<"Error!!!"<<endl;
return false;
}
x=elements[top];
return true;
}
template<class T>
int SeqStack<T>::Get_Size() const
{
int Size_SeqStack;
Size_SeqStack=top+1;
return Size_SeqStack;
}
template<class T>
bool SeqStack<T>::Is_Full() const
{
if (top==maxsize-1)
{
return true;
}
else
return false;
}
template<class T>
bool SeqStack<T>::Is_Empty() const
{
if (top!=maxsize-1)
{
return true;
}
else
return false;
}
template<class T>
SeqStack<T>::~SeqStack()
{
delete []elements;
}
#endif // !defined(AFX_SEQSTACK_H__94EF3A76_EB42_4B3D_BE22_1B9F8E253D2D__INCLUDED_)
SeqStack.cpp
SeqStack.cpp
// SeqStack.cpp: implementation of the SeqStack class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "SeqStack.h"
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
这篇关于找到了意外的文件结尾,这是我弄错了什么.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!