Paste the code First:
#include "stdafx.h" #include <iostream> #include <list> #include <ctime>using namespace std;void Mysleep (int second) {clock_t st;st=clock ();//The program takes CPU time from boot to function call while (clock ()-st<second*clocks_per_sec);//# Define CLOCKS_PER_SEC 1000}int _tmain (int argc, _tchar* argv[]) {int count = 5;int number=0;list<int> mylist; cout<< "Please enter any 5 numbers:" <<endl;while (count--) {cin>>number;mylist.push_back (number);//press data into List} List<int>::iterator iter;cout<< "Output the number just entered:" <<endl;for (Iter=mylist.begin (); Iter!=mylist.end (); iter++)//iterator {cout<<*iter<< ""; Mysleep (*iter);} Cout<<endl;system ("pause"); return 0;}
The principle of the delay program is very simple, is simple to get the program to invoke the clock () function CPU time, and then use a while loop, always call this function until the initial call and the current time of the last call to set the delay number jump out of the loop.
List,stack,vector the use of these containers I now feel more similar, I have just started to look at the STL standard library, not too clear, will only use an iterative loop, followed by a lot of this knowledge.
An example of a simple list class template in an STL library and a small delay program