Some iterators (iterator) use: C ++

#include <The iomanip> 
#include <the iostream> 
#include <Vector> 
#include <algorithm> the using namespace STD;
 the using STD :: Vector; int main () 
{ String Word ( " asdfgh " ); // initialization string Word 
    Vector < String > ivec ( 10 , " asdfgh " ); // ivec contains 10 elements the while (CIN >> Word) // encounters a blank stop     {
         / * 
        the begin member function returns a pointer to the first element of the container;

 


    
    
 
        End is not a member function returns an iterator pointing to the last element, instead iterator position behind a last element;
         
        Transform (first1, last1, first2, Result, binary_op); 
        first1 iterator is the first of the first container , last1 to a first end of the container iterators, 
        first2 first iterator to the second container, result is the result storage container; 
        * / 
        Transform (word.begin (), word.end (), ivec.begin ( ), toupper); 
        // ivec.push_back (Word); 
    }
     for (I & Auto: ivec) // I type string 
    { 
        COUT << I << endl; 
    } 
}

tansform function iterator range [first, last) elements, perform unary function (with an input variable) object op operation, the exchange results in [result, result + (last-first)) interval.

ivec.size = 10; 

Depending on the incoming word.size;

transform the interval [0,1] ivec replacement elements 
will be converted to uppercase and lowercase string progressive output:
#include <iomanip>
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;
using std::vector;

int main()
{
    string word("asdfgh"); //初始化字符串word
    vector<string>ivec;
    while (cin >> word) //遇到空白停止
    {

        transform(word.begin(), word.end(), word.begin(), toupper);
        ivec.push_back(word);
    }
    for (auto& i : ivec) //type string i 
    { 
        COUT << i << endl; 
    } 
}

 

Guess you like

Origin www.cnblogs.com/chenzexin/p/12546869.html