zoukankan      html  css  js  c++  java
  • C++ Primer 读书笔记 第十一章

    #include <algorithm>

    1. find()函数

    2. accumulate()函数

    3. find_first_of()函数的两个range的类型可以不同,但是两个range内部的类型必须相同。

    4. fill()函数,使用时必须保证空间是足够的。

        fill_n(back_inserter(vec), 10, 0);//appends 10 elements to vec

    5. replace()函数改变容器内部,replace_copy()函数不改变容器内部,而是自己新拷贝一份。

    6. sort()函数,unique()函数,unique_copy()函数,stable_sort()函数,count_if()函数

    7. back_inserter, front_inserter, inserter

        front_inserter requires push_front, so using front_inserter on a vector, or other container that does not have push_front, is an error.

        用front_inserter与用inserter(container, container.begin())效果不一样

    8. istream_iterator<T>与ostream_iterator<T>

        通过输入创建vector:

    istream_iterator<int> in_iter(cin);
    istream_iterator<int> eof;
    vector<int> vec(in_ter, eof);

    9. 学会用string(it1, it2)来新创建一个string

    10. reverse_iterator的base()函数

    11. Algorithms require the iterators that denote a range to have exactly the same type.

    12. input iterators                 ->istream_iterator

          output iterators              ->ostream_iterator

          forward iterators             ->replace()的参数

          bidirectional iterators       ->reverse()的参数

          random-access iterators  ->sort()的参数,vector,deque,string的iterators

    13. When dealing with algorithms, it is best to think of the iterators on associative containers as if they were input iterators that support decrement, not as full bidirectional iterators.

    14. list用其自身的成员函数,sort, unique, remove, reverse, merge, splice.

    #include <iostream>
    #include <algorithm>
    #include <numeric>
    #include <vector>
    #include <map>
    using namespace std;
    
    int main()
    {
        vector<string> vec;
        vec.push_back("jkl");
        vec.push_back("abc");
        vec.push_back("def");
        vec.push_back("abc");
        vec.push_back("ghi");
        string sum = accumulate(vec.begin(), vec.end(), string(""));//the third parameter cannot be "", which is const char *
        cout << sum << endl;
    
        sort(vec.begin(), vec.end());
        vector<string>::iterator end_unique = unique(vec.begin(), vec.end());
        for (vector<string>::iterator it = vec.begin(); it != end_unique; ++it)
            cout << *it << endl;
    
        string s1("abc");
        const char *s2 = "abc";
        if (s1 == s2)
            cout << true << endl;
        
        map<string, int> m;
        m.insert(make_pair("mbc", 1));
        m.insert(make_pair("edf", 1));
        m.insert(make_pair("ahe", 1));
        m.insert(make_pair("dwi", 1));
        m.insert(make_pair("waa", 1));
        //reverse(m.begin(), m.end());
        const vector<int> vc(10);
        return 0;
    }
  • 相关阅读:
    PIE SDK云图动画导出
    PIE SDK地图书签
    PIE SDK元素的保存与打开
    Jenkins简单入门:下载-安装-配置-构建
    Vue.js—60分钟快速入门
    程序员分享学习平台
    IOC+EF+Core项目搭建EF封装(一)
    python+django学习四
    python+django学习三
    Django2.0 应用 Xadmin 报错二
  • 原文地址:https://www.cnblogs.com/null00/p/3105301.html
Copyright © 2011-2022 走看看