• C++第七章经验整理


    The vector maintains a certain order of its elements, so that when a new element is inserted at the beginning or in the middle of the vector, Subsequent elements are moved backwards in terms of their assignment operator or copy constructor.

    Adapters are data types from STL that adapt a container to provide specific interface.

    Function objects are objects specifically designed to be used with a syntax similar to that of functions.

    <functional> header is need to be used with function objects.

    A sequence point defines any point in a computer program’s execution at which it is guaranteed that all side effects of previous evaluations have been performed.

    Sequence point is a point in time at which the dust has settled and all side effects which have been seen so far are guaranteed to be complete.

     A heap is a way to organize the elements of a range that allows for fast retrieval of the element.

    The min_element is used to compare the range of elements and it can find out the minimum element.

    Less than(<) operator is sufficient to compare any two elements in heap and construct respective min or max heap accordingly.

    There are 2 or 3 needed for next_permutation. They are first, last and optional comp for comparing the elements.

    There are five types of iterators. They are Output, Input, Forward, Random access and Bi-directional.

     Iterator pattern is a design pattern in which an iterator is used to traverse a container and access the container’s elements.

    Checked iterators ensure that you do not overwrite the bounds of your container.

    end()是不存在对应值的

    Checked iterator allow you to find Run time error.

    Checked iterators can easily detect the errors in Uninitialized iterators as well as Range of access.

    Allocators are implemented in C++ standard library but it is used for C++ template library.

    Because all the memory allocation and deallocation libraries are declared in <memory>.

    Input iterators can only be incremented and as it cannot be decremented it can be used in single-pass algorithms only.

    Input Iterators are used for accessing and Output Iterators are used for assigning.

    Both Input and Output iterators cannot be decremented therefore i2– is also wrong. Output iterators cannot be used with == operator, therefore, that is also wrong.

    random_shuffle() function is used to re-arrange a given sequence of elements in a range.

    stable sort is used to sort the elements of a sequence also preserving the relative order of the equivalent elements.

    partial sort of STL algorithm is used to sort the given elements before the middle element in ascending order without any specific order of elements after the middle element.

    STL provides accumulate() function to find the sum of a vector.

    <numeric> header file is required to use accumulate function in a program.

    () operator is overloaded to use functor property in a C++ program because this is the only operator used for a function call.

    Functors are objects of a class which also have other members and member functions which can be used to save states of that functors hence functors have a state. Functors can be declared anywhere in a program.

    f(arg1, arg2) means we are calling the overlaoded () operator method which can be called using object f as follows f.operator()(arg1,arg2); In general, object.operator()(argument_lists);

    缺省时,C++的文件是用txt的格式来读的。

     seekg() function is used to reposition a file pointer in a file. The function takes the offset and relative position from where we need to shift out pointer.

    ios::beg is used to reposition the file pointer to the beginning of the file. It is whenever you want to reposition the pointer at the beginning from any point to the start of the file.

    The member function seekg is used to position back from the end of file object.

    The member function is_open can be used to determine whether the stream object is currently associated with a file.

    <fstream> header file contains all the file reading and writing functions. Also <ifstream> and <ofstream> contains functions only reading and only writing to files related functions respectively.

  • 相关阅读:
    假期第五天
    假期第四天
    假期第三天
    假期第二天
    假期第一天
    《如何高效学习》读书笔记六
    十天冲刺-第八天
    十天冲刺第七天
    十天冲刺-第六天
    十天冲刺-第五天
  • 原文地址:https://www.cnblogs.com/hhlys/p/13521880.html
Copyright © 2020-2023  润新知