Hello i need help i cant figure out this error can any one help?
The error is cpp no match for 'operator<<' in 'std::cout << ordered' at 30, 31,32, 82, 83, 84
#include <cstdlib>
#include <iostream>
#include "stack.h"
usingnamespace std;
int main(int argc, char *argv[])
{
stack ordered;
stack temp1;
stack temp2;
int number;
int item;
cout << "Enter the number of elements in the stack: ";
cin >> number;
for (int i=0; i < number; i++)
{
item = rand()%100 + 1;
temp1.push(item);
}
cout<<"Stacks at the start: "<<endl;
cout << ordered;
cout << temp1;
cout << temp2;
while(!temp1.empty() || !temp2.empty())
{
if(temp2.empty())
{
stack temp = temp1;
int largest = temp1.pop();
while(!temp1.empty())
{
int element = temp1.pop();
if (largest < element)
largest = element;
}
while(!temp.empty())
{
int element = temp.pop();
if (element!=largest)
temp2.push(element);
}
ordered.push(largest);
}
else
{
stack temp=temp2;
int largest = temp2.pop();
while(!temp2.empty())
{
int element = temp2.pop();
if (largest < element)
largest = element;
}
while(!temp.empty())
{
int element = temp.pop();
if (element!=largest)
temp1.push(element);
}
ordered.push(largest);
}
cout << ordered;
cout << temp1;
cout << temp2;
}
system("PAUSE");
return EXIT_SUCCESS;
}
#include <iostream>
#include <cstdlib>
usingnamespace std;
constint stack_size = 1000;
class stack
{
private:
int data [stack_size]; // data for the stack
int top; // index of the top of the stack
public:
stack (); // creates an empty stack
void push (int item); // puts item on the top of the stack
int pop (); // removes and returns the top of the stack
bool full (); // returns true if the stack is full
bool empty (); // returns true if the stack is empty
void print ();
};
// constructor creates an empty stack
stack::stack ()
{
top = -1;
}
// push adds a new elment, item, to the top of the stack
void stack::push (int item)
{
// if the stack is full, print an error message
if (full ())
{
cout << "\n\nStack Error: Pushing on a full stack";
cout << "\nThe element being pushed was: " << item;
}
else // OK to push an element
{
top++;
data [top] = item;
}
}
// pop removes and returns the top element of the stack
int stack::pop ()
{
// if the stack is empty, print an error message
if (empty ())
{
cout << "\n\nStack Error: Popping an empty stack";
cout << "\nReturning ?";
return -1;
}
else // OK to pop
{
top--;
return data [top + 1];
}
}
// empty returns true if the stack is empty, else it returns false
bool stack::empty ()
{
return top == -1;
}
// full returns true if the stack is full, else it returns true
bool stack::full ()
{
return top == stack_size - 1;
}
void stack::print()
{
int item;
if (empty())
{
cout << "EMPTY";
}
while(!empty())
{
item=pop();
cout << item << " ";
}
cout << endl;
}
ok forsaken, I guess the question is, what exactly do you want output from those stack objects in lines 30-32? ..maybe some sample output?
Maybe you should operate on members of those objects separately instead of trying to "cout<<" the object itself..