Sei sulla pagina 1di 1

10/6/12

Search: Reference C++


Information Documentation Reference Articles Forum

list::assign - C++ Reference


Go
N ot logged in

STL Containers

list

assign

register

log in

public member function std::

list::assign

<it ls>

tmlt <ls Ipttrtr epae cas nuIeao> vi asg (Ipttrtrfrt Ipttrtrls ) od sin nuIeao is, nuIeao at ; vi asg (sz_yen cntT u) od sin ietp , os & ; Assign new content to container Assigns new content to the container, dropping all the elements contained in the container object before the call and replacing them by those specified by the parameters: In the first version (with iterators), the new contents of the container object is a copy of those contained in the sequence between first and last (in the range [ i s , a t ). frtls) In the second version, the new content is the repetition n times of copies of element u.

Reference
C Library IOstream Library Strings library STL Containers STL Algorithms Miscellaneous

STL Containers
array bitset deque forward_list list map multimap multiset priority_queue queue set stack unordered_map unordered_multimap unordered_multiset unordered_set vector

Parameters
first, last Input iterators to the initial and final positions in a sequence. The range used is [ i s , a t , which frtls) includes all the elements between first and last, including the element pointed by first but not the element pointed by last. The template type can be any type of input iterator. n Times that u is repeated to form the new content of the object. Member type s z _ y eis an unsigned integral type. ietp u Value to be repeated n times as the new content of the object. Tis the first class template parameter (the type of the elements stored in the list container).

Return value
none

list
comparison operators list::list list::~list member functions: list::assign list::back list::begin list::clear list::empty list::end list::erase list::front list::get_allocator list::insert list::max_size list::merge list::operator= list::pop_back list::pop_front list::push_back list::push_front list::rbegin list::remove list::remove_if list::rend list::resize list::reverse list::size list::sort list::splice list::swap list::unique

Example
1/ l s : a s g / it:sin 2# n l d < o t e m icue isra> 3# n l d < i t icue ls> 4u i g n m s a e s d sn aepc t; 5 6i t m i ( n an ) 7{ 8 ls<n>frt itit is; 9 ls<n>scn; itit eod 1 0 1 1 frtasg (,0) is.sin 710; / 7it wt vle10 / ns ih au 0 1 2 1 3 scn.sin(is.ei(,is.n() / acp o frt eodasg frtbgn)frted); / oy f is 1 4 1 5 itmit[=17,,} n yns]{7674; 1 6 frtasg (ynsmit+) is.sin mit,yns3; / asgigfo ary / sinn rm ra 1 7 1 8 cu < "ieo frt "< it(is.ie) < ed; ot < Sz f is: < n frtsz() < nl 1 9 cu < "ieo scn:"< it(eodsz()< ed; ot < Sz f eod < n scn.ie) < nl 2 0 rtr 0 eun ; 2 } 1 Output: Sz o frt 3 ie f is: Sz o scn:7 ie f eod

Complexity
Linear on initial and final sizes (destruction, copy construction).

See also
list::operator= Copy container content (public member function)

H ome page | P rivac y polic y c plus plus .c om, 2 0 0 0 - 2 0 1 2 - A ll rights res erved - v3.1 Spotted an error? c ontac t us

www.cplusplus.com/reference/stl/list/assign/

1/1

Potrebbero piacerti anche