0,构造函数列表
std::vector<T,Allocator>::vector - cppreference.com
vector();
(until C++17)
vector() noexcept(noexcept(Allocator()));
(since C++17)
(until C++20)
constexpr vector() noexcept(noexcept(Allocator()));
(since C++20)
(2)
explicit vector( const Allocator& alloc );
(until C++17)
explicit vector( const Allocator& alloc ) noexcept;
(since C++17)
(until C++20)
constexpr explicit vector( const Allocator& alloc ) noexcept;
(since C++20)
(3)
explicit vector( size_type count,
const T& value = T(),
const Allocator& alloc = Allocator() );
(until C++11)
vector( size_type count,
const T& value,
const Allocator& alloc = Allocator() );
(since C++11)
(until C++20)
constexpr vector( size_type count,
const T& value,
const Allocator& alloc = Allocator() );
(since C++20)
(4)
explicit vector( size_type count );
(since C++11)
(until C++14)
explicit vector( size_type count,
const Allocator& alloc = Allocator() );
(since C++14)
(until C++20)
constexpr explicit vector( size_type count,
const Allocator& alloc = Allocator() );
(since C++20)
(5)
template< class InputIt >
vector( InputIt first, InputIt last,
const Allocator& alloc = Allocator() );
(until C++20)
template< class InputIt >
constexpr vector( InputIt first, InputIt last,
const Allocator& alloc = Allocator() );
(since C++20)
(6)
vector( const vector& other );
(until C++20)
constexpr vector( const vector& other );
(since C++20)
(7)
vector( const vector& other, const Allocator& alloc );
(since C++11)
(until C++20)
constexpr vector( const vector& other, const Allocator& alloc );
(since C++20)
(8)
vector( vector&& other );
(since C++11)
(until C++17)
vector( vector&& other ) noexcept;
(since C++17)
(until C++20)
constexpr vector( vector&& other ) noexcept;
(since C++20)
(9)
vector( vector&& other, const Allocator& alloc );
(since C++11)
(until C++20)
constexpr vector( vector&& other, const Allocator& alloc );
(since C++20)
(10)
vector( std::initializer_list<T> init,
const Allocator& alloc = Allocator() );
(since C++11)
(until C++20)
constexpr vector( std::initializer_list<T> init,
const Allocator& alloc = Allocator() );
(since C++20)
template< container-compatible-range<T> R >
constexpr vector( std::from_range_t, R&& rg,
const Allocator& alloc = Allocator() );
(11) (since C++23)
1,ex01
template< class InputIt >
constexpr vector( InputIt first, InputIt last,
const Allocator& alloc = Allocator() );
#include <vector>
#include <iostream>
using namespace std;
int main()
{
char A[12] ={'a','b','c','d','e','f','g','h','i','j','k','l'};
cout<<A<<endl;
vector<char> B(A+2,A+4);
cout<< B.size()<<endl;
for(int i=0; i<B.size(); i++)
cout<<B[i]<<endl;
return 0;
}
Makefile:
hello:
.PHONY: clean
clean:
${RM} hello
ex02
ex03
ex04
ex05
未完待续