C++;队列,运行时故障检查#最大队列大小为2 我对C++仍然是新的,我不知道如何修复这个错误。我需要代码做的是创建一个接收用户输入的队列,但是如果他们输入超过10个输入,那么他们应该会收到一条错误消息 #include <iostr
C++;队列,运行时故障检查#最大队列大小为2 我对C++仍然是新的,我不知道如何修复这个错误。我需要代码做的是创建一个接收用户输入的队列,但是如果他们输入超过10个输入,那么他们应该会收到一条错误消息C++;队列,运行时故障检查#最大队列大小为2 我对C++仍然是新的,我不知道如何修复这个错误。我需要代码做的是创建一个接收用户输入的队列,但是如果他们输入超过10个输入,那么他们应该会收到一条错误消息 #include <iostr,c++,runtime,C++,Runtime,C++;队列,运行时故障检查#最大队列大小为2 我对C++仍然是新的,我不知道如何修复这个错误。我需要代码做的是创建一个接收用户输入的队列,但是如果他们输入超过10个输入,那么他们应该会收到一条错误消息 #include <iostream> #include <cstdlib> using namespace std; const int MAX_QUE_SIZE = 10; class QueueOverFlowException { public
#include <iostream>
#include <cstdlib>
using namespace std;
const int MAX_QUE_SIZE = 10;
class QueueOverFlowException {
public:
QueueOverFlowException() {
cout << "QUEUE OVERFLOW" << endl;
}
};
class QueueEmptyException {
public:
QueueEmptyException()
{
cout << "EMPTY QUEUE" << endl;
}
};
class queue {
private:
int data[MAX_QUE_SIZE];
int front;
int rear;
public:
queue() {
front = -1;
rear = -1;
}
void enqueue(int element) {
if (queuesize() == MAX_QUE_SIZE - 1)
throw new QueueOverFlowException();
data[rear] = element;
rear = ++rear % MAX_QUE_SIZE;
}
int dequeue() {
if (isEmpty())
throw new QueueEmptyException();
int i = data[front];
front = ++front % MAX_QUE_SIZE;
return i;
}
int queuefront() {
if (isEmpty())
throw new QueueEmptyException();
return data[front];
}
int queuesize() {
return abs(rear - front);
}
bool isEmpty() {
return (front == rear) ? true : false;
}
};
int main(){
queue q;
int i;
std::cout << "Please enter some integers (enter 0 to exit):\n";
do {
std::cin >> i;
q.enqueue(i);
} while (i != 0);
std::cout << endl;
return 0;
}
#包括
#包括
使用名称空间std;
const int MAX_QUE_SIZE=10;
类QueueOverFlowException{
公众:
QueueOverFlowException(){
你能告诉我们导致运行时错误的输入吗?另外,你能告诉我们你在使用什么编译器吗?我刚刚用g++版本4.8.4编译了你的示例,并且能够以预期的结果运行代码(例如,输入[1-10]时抛出异常,输入[1,2,3,4,5,6,7,8,0]时正常完成程序)