-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathassign.html
More file actions
115 lines (96 loc) · 3.29 KB
/
assign.html
File metadata and controls
115 lines (96 loc) · 3.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<!-- Mirrored from cppreference.com/cppdeque/assign.html by HTTrack Website Copier/3.x [XR&CO'2004], Tue, 22 Jan 2008 06:25:35 GMT -->
<!-- Added by HTTrack --><meta http-equiv="content-type" content="text/html;charset=iso-8859-1"><!-- /Added by HTTrack -->
<head>
<meta name="generator" content=
"HTML Tidy for Linux/x86 (vers 1 September 2005), see www.w3.org">
<title>assign</title>
<link href="../cppreference.css" rel="stylesheet" type="text/css">
<link href="../prettify.css" type="text/css" rel="stylesheet" />
<script type="text/javascript" src="../prettify.js"></script>
</head>
<body onload="prettyPrint()">
<table>
<tr>
<td>
<div class="body-content">
<div class="header-box">
<a href="../index-2.html">cppreference.com</a> > <a href=
"index.html">C++ Double-ended Queues</a> > <a href=
"assign.html">assign</a>
</div>
<div class="name-format">
assign
</div>
<div class="syntax-name-format">
Syntax:
</div>
<pre class="syntax-box">
#include <deque>
void assign( <strong>size_type</strong> num, const <a href=
"../containers.html">TYPE</a>& val );
void assign( <a href=
"../iterators.html">input_iterator</a> start, <a href=
"../iterators.html">input_iterator</a> end );
</pre>
<p>The assign() function either gives the current dequeue the values
from <em>start</em> to <em>end</em>, or gives it <em>num</em> copies
of <em>val</em>.</p>
<p>This function will destroy the previous contents of the
dequeue.</p>
<p>For example, the following code uses assign() to put 10 copies of
the integer 42 into a vector:</p>
<pre class="prettyprint">
vector<int> v;
v.assign( 10, 42 );
for( int i = 0; i < v.size(); i++ ) {
cout << v[i] << " ";
}
cout << endl;
</pre>
<p>The above code displays the following output:</p>
<pre class="prettyprint">
42 42 42 42 42 42 42 42 42 42
</pre>
<p>The next example shows how assign() can be used to copy one vector
to another:</p>
<pre class="prettyprint">
vector<int> v1;
for( int i = 0; i < 10; i++ ) {
v1.push_back( i );
}
vector<int> v2;
v2.assign( v1.begin(), v1.end() );
for( int i = 0; i < v2.size(); i++ ) {
cout << v2[i] << " ";
}
cout << endl;
</pre>
<p>When run, the above code displays the following output:</p>
<pre class="prettyprint">
0 1 2 3 4 5 6 7 8 9
</pre>
<div class="related-name-format">
Related topics:
</div>
<div class="related-content">
(C++ Strings) <a href="../cppstring/assign1.html">assign</a><br>
<a href="insert.html">insert</a><br>
<a href="push_back.html">push_back</a><br>
<a href="push_front.html">push_front</a>
</div>
</div>
</td>
<script src="../../www.google-analytics.com/urchin.js" type="text/javascript">
</script>
<script type="text/javascript">
_uacct = "UA-2828341-1";
urchinTracker();
</script>
</tr>
</table>
</body>
<!-- Mirrored from cppreference.com/cppdeque/assign.html by HTTrack Website Copier/3.x [XR&CO'2004], Tue, 22 Jan 2008 06:25:35 GMT -->
<!-- Added by HTTrack --><meta http-equiv="content-type" content="text/html;charset=iso-8859-1"><!-- /Added by HTTrack -->
</html>