读书人

一个有关问题啊帮帮忙啊

发布时间: 2012-02-28 13:06:35 作者: rapoo

请教大家一个问题啊,帮帮忙啊~~~
请问错误是怎么改啊?
编译是老是有错误
程序如下:

#include <iostream.h>
#include <ctype.h>
#include <iomanip.h>
#include <stdio.h>
#include <sstream>
#include <cstring>
using namespace std;
#define MAX_SIZE 100

template <class T> class Stack
{
T data[MAX_SIZE];
int top;

public:

Stack(void);
~Stack(void);
bool empty(void);
void push(T a);
T pop(void);
T GetTop(void);
};

template <class T> Stack <T> ::Stack(void)//构造函数
{
top=-1;
}

template <class T> Stack <T> ::~Stack(void)//析构函数
{
}

template <class T> bool Stack <T> ::empty(void)//判断栈空操作
{
return top==-1?true :false;
}
template <class T> void Stack <T> ::push(T a)//入栈操作
{
if(top==MAX_SIZE)
{
cout < < "Stack is full! " < <endl;
return;
}

data[++top]=a;
}

template <class T> T Stack <T> ::pop(void)//出栈操作
{
if(top==-1)
{
cout < < "Stack is underflow! " < <endl;
return 0;
}
return data[top--];
}
template <class T> T Stack <T> ::GetTop(void)//取栈头元素操作
{
if(top!=-1)
return data[top];
else return false;
}



void main()
{

string s1;
Stack <string> st;
st.push(s1);
cout < <st.pop();//错误位置
}


/*错误提示
error C2679: binary ' < < ' : no operator defined which takes a right-hand operand of type 'class std::basic_string <char,struct std::char_traits <char> ,class std::allocator <char> > ' (or there is n
o acceptable conversion)
*/

[解决办法]
楼主用的VC6吧,还又受垃圾书籍误导
#include <iostream>
#include <iomanip>
#include <sstream>
#include <string>
using namespace std;
[解决办法]
C++ 方式 include 头文件 ...
------解决方案--------------------


不跟.h,把命名库加上 就向taodm说的一样
taodm今天没使用你的okok吗 哈哈
[解决办法]
我喜欢学习那个C++
我的QQ号码是 690265281 加我的时候写上C++ 就可以了
我们可以一起讨论
谢谢

读书人网 >C++

热点推荐