List container in STL
// Add, delete, search, and insert a string list # include "stdafx. H "# include <iostream> # include <string> # include <list> using namespace STD; int main () {list <string> olist; // List objects cannot be directly operated on. They can only be operated through algorithms or iterators. // olist [0] = "www.jiesoon.com "; // No // no reserved space for the list // olist. capacity (); // no such function // Add the olist element to the olist object. push_back ("3.jiesoon.com"); olist. push_front ("2.jiesoon.com"); olist. push_back ("4.jiesoon.com"); olist. push_front ("1. Jiesoon.com "); List <string >:: iterator itlist = olist. Begin (); For (; itlist! = Olist. end (); ++ itlist) {cout <* itlist <Endl;} cout <"olist existing elements:" <olist. size () <Endl; cout <"************************************ * ********* "<Endl; // list is a bidirectional linked list vector deque. You can also use the iterator to bidirectional access itlist = olist. begin (); // itlist + = 2; // No. List is not a continuous container + + itlist; ++ itlist; cout <* itlist <Endl; -- itlist; cout <* itlist <Endl; cout <"************************************ ********** "< <Endl; // insert data (unlike vector, deque inserts data in different locations with the same efficiency) itlist = olist. begin (); olist. insert (itlist, "0.jiesoon.com"); For (itlist = olist. begin (); itlist! = Olist. end (); ++ itlist) {cout <* itlist <Endl ;} cout <"************************************ * ********* "<Endl; // data deletion method ① olist. remove ("2.jiesoon.com"); For (itlist = olist. begin (); itlist! = Olist. end (); ++ itlist) {cout <* itlist <Endl ;} cout <"************************************ * ********* "<Endl; // data deletion method ② itlist = olist. begin (); olist. erase (itlist); For (itlist = olist. begin (); itlist! = Olist. End (); ++ itlist) {cout <* itlist <Endl;} return 0 ;}