C++ Can';t获取填充堆栈的顶部元素<;char>;
我坚持使用堆栈)在这段代码中,我填充了一些堆栈,然后试图从中获取日期。但是使用char stack时,我遇到了一个问题错误 在标头中声明堆栈C++ Can';t获取填充堆栈的顶部元素<;char>;,c++,stack,C++,Stack,我坚持使用堆栈)在这段代码中,我填充了一些堆栈,然后试图从中获取日期。但是使用char stack时,我遇到了一个问题错误 在标头中声明堆栈 stack<int> numbers; stack<char> operators; 堆栈编号; 堆栈运算符; 输入法 void Notation::InptWriter() { notationPtr = new char[SIZE]; cout << "Enter expression: ";
stack<int> numbers;
stack<char> operators;
堆栈编号;
堆栈运算符;
输入法
void Notation::InptWriter() {
notationPtr = new char[SIZE];
cout << "Enter expression: ";
cin.getline(notationPtr, SIZE);
}
void表示法::InptWriter(){
notationPtr=新字符[大小];
cout在测试opers
ansnums
while (!opers.empty() && !nums.empty()){
其中,正如在循环中一样,您使用运算符
和数字
op = operators.top();//Problem over there
operators.pop();
num = numbers.top();
numbers.pop();
请参阅公开代码中的工作示例,没有任何std::stack
的单个声明/定义。请提供一个。什么运行时错误?您确定该堆栈是由char
组成的吗?为什么要使用typeid
?它在弹出元素的析构函数中似乎失败。抱歉,问题不清楚。我添加了有关声明堆栈的信息。typeid
我用于检查堆栈中的值,以防堆栈存储不同的数据类型值。我推荐了一行代码,其中我查看堆栈顶部,所有内容都开始工作…if(!operators.empty()){//cout Thank you.它保留了以前的版本,我将其更改为,而(!operators.empty()&&&&!numbers.empty())
,但无论如何都得到了相同的错误。我添加了一个工作示例,表明当一致地使用opers
和nums
时,代码可以工作(不会崩溃)。提供一个。
if (!operators.empty()) {
// cout << "op: " << operators.top();
}
if (!numbers.empty()) {
// cout << "__Num: " << numbers.top();
while (!opers.empty() && !nums.empty()){
op = operators.top();//Problem over there
operators.pop();
num = numbers.top();
numbers.pop();