Learning vc ++ on the third day

Cpp original copy constructor must be rewritten after writing assignment operator, otherwise the problem will be re-releasable memory.


Learn the collection type, found _Pop_back_n vector of the cpp () function has been unable to use vs2019 .. looks like the role is not large .. hehe

cpp of vector and c # list of similar, but the list did not seem cpp corresponding c # operation ...

Because I rewriting c # iterator supports through the above type,
which is not a duplicate added: List <Tl, T2, T3>,
c # own support and only a repeating generic template: list <T>,
so It may be reproduced achieved over the past functions in cpp above, it is more sensitive collection type of use.

vector means a vector, the vector is continuous,
and the list is a linked list can be accessed is broken,
as shown wishful speed required to get to see the name can be associated, to name them are quite interesting person.

 

And then found cpp of std (Standard Template Library) is no hump nomenclature, very bad, because the knock on c # people like this distinction between functions and variables ...

 

cpp quite interesting, int can not be written int, size_t ... because it is considered to be written as a 64-bit version ...
So many times we must look at the internal code ..

 

Today assignments and learning to manipulate strings, the main form of operation is to char .. char * .. const char * .. and then string..str.c_str () understanding ...

 

Learning mess of code:

#include <iostream>
#include <vector>
#include <list>
#include <map>
using namespace std;

int main ()
{
    {
        vector<int> arr_int;
        vector<int> arr_int2(4, 88);
        vector<int> arr_int3 = arr_int2;
        vector<int> arr_int4(arr_int3.begin(), arr_int3.end());
        for (size_t i = 0; i < 6; i++)
        {
            arr_int4.push_back(666);
        }

        int szint [ 10 ] = { 2 , . 3 , . 6 , . 9 , . 8 , . 7 , 899 , . 4 };
         // copy of the first address, the copy length 
        Vector < int > arr_int5 (szint, + szint the sizeof (szint) / the sizeof ( int ));
         int A = arr_int5 [ . 5 ];
        cout << "a=" << a << endl;
        cout << "int5 的大小是:" << arr_int5.size() << endl;
        cout << "11111 =" << arr_int5.front() << endl;
        cout << "end =" << arr_int5.back() << endl;
        //arr_int5.clear();

        {
            vector<string*> arr_string;
            string* str;
            string stra = "试试";
            p = & stra;
            arr_string.push_back(str);
            arr_string.push_back(str);
            arr_string.push_back(str);
            stra = "hhhhhh";
            arr_string.push_back(str);
            arr_string.push_back(str);
        }


        if (arr_int5.size() > 5)
        {
            arr_int5.insert(arr_int5.begin() + 2, 3, 666);
            int szint2[] = { 15, 25,35 };
            arr_int5.insert(arr_int5.end(), szint2, szint2 + sizeof(szint2) / sizeof(int));
            arr_int5.pop_back();
            arr_int5.erase (arr_int5.begin () + 2 , arr_int5.begin () + . 4 ); // delete the range to what extent from what 
        }

        // traversal operation 
        for ( int IDX = 0 ; IDX <arr_int5.size (); ++ IDX)
        {
            int value = arr_int5[idx];
            cout << value << ",";
        }
        cout << endl;
         // use iterator traversal iterator is at the beginning and end pointer 
        for (the Vector < int > :: Iterator itor = arr_int5.begin ();! itor = arr_int5.end (); ++ itor)
        {
            int value = *itor;//解引用
            cout << value << ",";
        }
        cout << endl;

        list<int> ls(arr_int5.begin(), arr_int5.end());

        List < int > = {LS2 . 1 , . 4 , . 3 , . 3 , . 3 , . 7 , . 9 , . 3 , . 6 , . 8 , . 3 , . 5 , 2 , . 3 , . 7 };
         // ls2.remove (. 3); // this 3 you can delete the Lord, required for the non-subject method

        //用for方法
        for (list<int>::iterator itor = ls2.begin(); itor != ls2.end();)
        {
            int value = * itor; // dereferencing 
            IF (* == itor . 3 )
            {
                // After removing the iterator destroyed, then go back to pass under an iterator 
                itor = ls2.erase (itor);
            }
            else
            {
                itor++;
            }
        }

        for (list<int>::iterator itor = ls2.begin(); itor != ls2.end(); itor++)
        {
            int value = *itor;//解引用
            cout << value << ",";
        }
        cout << endl;

        map<int, char> stud_sex_map;
        int n_size = stud_sex_map.size();
        bool is_empty = stud_sex_map.empty();//是否为空
        stud_sex_map[10010] = 'm';
        stud_sex_map[10011] = 'f';
        char ch = stud_sex_map[10010];

        if (!stud_sex_map.count(10012) > 0)//!含有
        {
            stud_sex_map[10012] = 'm';
        }
        ch = stud_sex_map[10012];
        stud_sex_map.erase(10010);
        stud_sex_map.erase(--stud_sex_map.end());

        // traverse key-value pairs 
        for (the Map < int , char > :: Iterator itor = stud_sex_map.begin ();! Itor = stud_sex_map.end (); ++ itor)
        {
            int key = itor->first;
            char ch = itor->second;
            cout << "key =" << key << ",value = " << ch << endl;
        }
        cout << endl;
        cout << endl;
        cout << endl;


        map<int, char> rilige;
        units provide [ 10010 ] = ' m ' ;
        units provide [ 10013 ] = ' m ' ;
        units provide [ 10015 ] = ' m ' ;

        units provide [ 10011 ] = ' b ' ;
        units provide [ 10012 ] = ' b ' ;
        rilige [ 10014 ] = ' F ' ;
         // automatically sorted 
        for (Map < int , char > :: = rilige.begin itor Iterator (); itor =! rilige.end ();)
        {
            int key = itor->first;
            char ch = itor->second;
            if (ch == 'f')
            {
                // After removing the iterator destroyed, then go back to pass under an iterator 
                itor = rilige.erase (itor);
            }
            else
            {
                itor++;
                cout << "key =" << key << ",value = " << ch << endl;
            }
        }


        {
            string str;
            str.assign("aaaaaaaaaaaaaa");
            cout << str << endl;
            const char* p23 = "hello, cctry.com";

            str.clear();
            str.assign (P23); // pointer assignment method 
            COUT STR << << endl;

            str.clear();
            str.assign (P23, . 7 , 91 is ); // pointer assignment method 
            COUT STR << << endl;

            cout << str + str << endl;

            STR = " . cctry.com Hello, cctry.com byebye " ;
             // STR = "Hello cctry.com, byebye."; 
            size_t IPOS = str.find ( " cctry.com " ); // return position found 
            if (IPOS> 0 ) // is to find 
            {
                 const  char * CA = str.c_str ();
                ipos2 size_t = str.find ( " cctry.com " , IPOS + 1 ); // Returns Found positions, to be able to add 1 to find the next 
                IF (ipos2> 0 ) // is to find 
                {

                }
            }
            str.replace(0, 5, "zhangsan");//替换 
            cout << str << endl;

            str.insert(0, "lisi ");
            cout << str << endl;

            str.insert(0, 3, 'v');
            cout << str << endl;
        }

        {
            vector<char> vec;
            string vecstring;//存放新的
            string strasd("123#ab##cctry.com#");
            for (size_t i = 0; i < strasd.size(); i++)
            {
                char pn = strasd[i];
                if (pn != '#')
                {
                    vec.push_back(pn);
                    vecstring.push_back(pn);
                }
            }
        }
          

    }
    std::cin.get();
    return 0;
}
View Code

 

Guess you like

Origin www.cnblogs.com/JJBox/p/12508054.html
Recommended