An example of a simple list class template in an STL library and a small delay program

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.