STL uses vector

xiaoxiao2021-04-08  366

#include // STL Vector header file. Note that there is no ".h" #include // need to use coutusing namespace std; // Make sure the namespace is STD

Char * szhw = "Hello World"; / / It is well known that this is an array of characters ending with NULL

INT Main (int Argc, char * argv []) {Vector vec; // A VECTOR of a character type (equivalent to array in STL)

/ / Define iterator Vector :: item VI;

// Initialize character vector, loop the entire string, put each character into the vector until the NULL character char * cptr = szhw; // Hello World string of the character string While (* CPTR! = ') 0 ') {vec.push_back (* cptr); CPTR ;} // push_back function Plug the data into the vectors of the VECTOR

/ / Print each character in the STL array to the screen for (vi = vec.begin (); vi! = Vec.eGin (); vi ) // This is the standard judgment method in the STL cycle - often Use "! =" Rather than "<" // may not have a heavy load operator "<". // begin () and end () get an iterator (pointer) {cout << * vi;} // using indirect operator (*) from the iterator (*) from the iterator (*)

Return 0;}

转载请注明原文地址:https://www.9cbs.com/read-132726.html

New Post(0)