#include <iostream>
#include <stack>
#include <string>
using namespace std;
int main()
{
string name;
double gpa;
double high = 0;
stack<string>names;
for (int i=0;i<7;i++)
{
cout << " Enter student's name and gpa " <<endl;
cin >> gpa ;
cin >> name ;
if (gpa > high)
{
names.destroyStack();
high = gpa;
names.push(name);
}
else
if (gpa==high)
{
names.push(name);
}
}
cout << "Highest gpa is " << high << "Names with the highest gpa are"<< endl;
while (!names.empty)
{
cout << names.top() << endl;
names.pop();
}
return 0;
}
为了只显示最高gpa的名字,我必须提供一个代码,以便在较低的gpa值之前删除堆栈。因此,我认为我可以使用“destroystack()”操作,但是当我使用它并尝试执行它时,编译器说destroyStack没有在范围内声明。为什么说我的'摧毁堆'没有被宣布?
这是我想要显示堆栈的最下面一个,它甚至说没有声明为空。 我对这些错误感到困惑,我不知道通过声明操作是什么意思?我正在使用代码块(不是Visual Studio),那么这会影响任何东西吗?
除此之外,你为什么会使用堆栈呢? – 2011-03-12 03:41:14
同意。我没有看到任何理由在这里使用堆栈。 – 2011-03-12 16:47:29