It is found that in normal coding, the frequency of stack and queue is very high, and it is difficult to write a stack and queue by yourself. Today we are specially studying how to use the stack and queue in STL. The research is not input, but simple usage.
The following is an example of my stack and queue usage.Code
# Include <iostream> <br/> # include <stack> <br/> # include <queue> <br/> # include <stdlib. h> // system ("pause"); <br/> using namespace STD; <br/> int main () <br/>{< br/> stack <int> S; <br/> queue <int> q; <br/> int arry [4] = {1, 2, 3, 4}; <br/> for (INT I = 0; I <4; I ++) <br/> {<br/> S. push (arry [I]); <br/> q. push (arry [I]); <br/>}< br/> // elements in the output stack <br/> cout <"Stack length:" <S. size () <Endl; <br/> for (INT I = 0; I <4; I ++) <br/>{< br/> cout <S. top () <"; <br/> S. pop (); <br/>}< br/> cout <Endl; <br/> // elements in the output queue <br/> cout <"the queue length is: "<q. size () <Endl; <br/> for (INT I = 0; I <4; I ++) <br/>{< br/> cout <q. front () <"; <br/> q. pop (); <br/>}< br/> cout <Endl; <br/>/* int I; <br/> CIN> I; */<br/> system ("pause"); <br/> return 0; <br/>}
PS:
When pressing CTRL + F5 in vs2010, the command line flashed through without the prompt "press any key to continue.
For online query, the final solution is to add the stdlib. h header file, as shown below:
# Include <stdlib. h> // system ("pause"); required
ThenProgramAdd system ("pause");. If return exists, write it before return. As follows:
System ("pause"); <br/> return 0;
There is also another method to solve the problem of a transient command line, please refer
Http://hi.baidu.com/liuguoyuhot/blog/item/f58f64edffae4a2826979108.html