Initiation of the dynamic mass



  • How to initiate the dynamic mass of whole numbers (intWhen it's announced?



  • Create. vector<int>♪ He has a designer:

    explicit vector (size_type n, const value_type& val = value_type(),
                     const allocator_type& alloc = allocator_type());
    

    Give it the number of elements and the primary value.

    Or you can put the initial values into this designer if you already have them:

    template <class InputIterator>
             vector (InputIterator first, InputIterator last,
                     const allocator_type& alloc = allocator_type());
    

    The use of the vector will solve all your problems with changing the size of the dynamic mass in the future.


    If you need a bare mass, you can fill it with zeros, recording it at the end of the box:

    new int[n]();
    

    Concrete values are maintained by modern compilators:

    new int[n] { 1, 2 };
    



Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2