J
Juri
Hi all,
I have a question regarding the << operator.
I wrote a simple queue class, which contains add(char), del() and empty() functions.
They works fine.
Now I want its output.
If I write the following way, it gives me the correct output.
while(!q1.empty()){ // This prints "abc"
cout<<q1.del();
}
However, if I write the following way, it gives me the wrong output sequence.
cout<< q.del() << q.del() << q.del(); // This prints "cba"
Can someone explain how the operator is working in these cases?
Please refer to the following main.
Thanks.
J
**********************************************************************8
int main()
{
queue q;
q.add('a');
q.add('b');
q.add('c');
cout<< q.del() << q.del() << q.del(); // This prints "cba" <-- Wrong!
cout<<"\n";
queue q1;
q1.add('a');
q1.add('b');
q1.add('c');
while(!q1.empty()){ // This prints "abc"
cout<<q1.del();
}
cout<<"\n";
return 0;
}
I have a question regarding the << operator.
I wrote a simple queue class, which contains add(char), del() and empty() functions.
They works fine.
Now I want its output.
If I write the following way, it gives me the correct output.
while(!q1.empty()){ // This prints "abc"
cout<<q1.del();
}
However, if I write the following way, it gives me the wrong output sequence.
cout<< q.del() << q.del() << q.del(); // This prints "cba"
Can someone explain how the operator is working in these cases?
Please refer to the following main.
Thanks.
J
**********************************************************************8
int main()
{
queue q;
q.add('a');
q.add('b');
q.add('c');
cout<< q.del() << q.del() << q.del(); // This prints "cba" <-- Wrong!
cout<<"\n";
queue q1;
q1.add('a');
q1.add('b');
q1.add('c');
while(!q1.empty()){ // This prints "abc"
cout<<q1.del();
}
cout<<"\n";
return 0;
}