Re: std::vector : begin, end and insert - Using Objects instead of ints
This is a multi-part message in MIME format.
------=_NextPart_000_0017_01C77BE7.D5F789E0
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
A Test of the emergency broadcast
std::vector<CPoint> m_Pts;
CPoint Pt(2, 4);
=
//-----------------------------------------------------------------------=
----------
// Fill Collection
=
//-----------------------------------------------------------------------=
----------
for (UINT i = 1; i < 11; i++)
{
CPoint Pt;
Pt.x = i;
Pt.y = i;
m_Pts.push_back(Pt);
}
=
//-----------------------------------------------------------------------=
----------
// at : Returns a reference to the element at a specified location in =
the vector.
=
//-----------------------------------------------------------------------=
----------
for (UINT i = 0; i < 10; i++)
{
CPoint& rPt = m_Pts.at(i);
TRACE("Pt[%d] Pt.x %d, Pt.y %d\n", i, rPt.x, rPt.y);
}
=
//-----------------------------------------------------------------------=
----------
// begin : A random-access iterator addressing the first element in the =
vector or
// to the location succeeding an empty vector. You should =
always compare
// the value returned with vector::end to ensure it is valid.
//
// end : A random-access iterator to the end of the vector object. You =
should
// compare the value returned to vector::begin to ensure it is =
valid.
//
=
//-----------------------------------------------------------------------=
----------
m_Pts.resize(20);
std::vector<CPoint>::const_iterator m_cIter;
// *c1_cIter = 200; Error. c1_cIter is constant.
m_cIter = m_Pts.begin();
TRACE("Position of Iterator: %d\n", *m_cIter);
std::vector<CPoint>::iterator m_Iter;
m_Iter = m_Pts.begin();
TRACE("Position of Iterator: %d\n", *m_Iter);
m_Iter = m_Pts.end();
TRACE("Position of Iterator: %d\n", *m_Iter);
*m_Iter = 10;
TRACE("Position of Iterator: %d\n", *m_Iter);
for (UINT i = 0; i < m_Pts.size(); i++)
{
CPoint& rPt = m_Pts.at(i);
TRACE("Pt[%d] Pt.x %d, Pt.y %d\n", i, rPt.x, rPt.y);
}
for(m_Iter = m_Pts.begin(); m_Iter < m_Pts.end(); m_Iter++)
{
CPoint& pt = m_Pts.at(*m_Iter);
TRACE("Pt[%d] Pt.x %d, Pt.y %d\n", pt.x, pt.y);
}
------=_NextPart_000_0017_01C77BE7.D5F789E0
Content-Type: text/html;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; =
charset=iso-8859-1">
<META content="MSHTML 6.00.6000.16414" name=GENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY>
<DIV><FONT face=Arial size=2>A Test of the emergency =
broadcast</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2> std::vector<CPoint> =
m_Pts;</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2> CPoint Pt(2, 4);</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial
size=2> //--------------------------------------------------------=
-------------------------<BR> //
Fill
Collection<BR> //---------------------------------------------------=
------------------------------<BR> for
(UINT i = 1; i < 11; i++)<BR> {<BR> CPoint Pt;<BR> =
Pt.x =
i;<BR> Pt.y = i;<BR> =
m_Pts.push_back(Pt);<BR> }</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial
size=2> //--------------------------------------------------------=
-------------------------<BR> //
at : Returns a reference to the element at a specified location in the
vector.<BR> //------------------------------------------------------=
---------------------------<BR> for
(UINT i = 0; i < 10; i++)<BR> {<BR> CPoint& rPt =
m_Pts.at(i);<BR> TRACE("Pt[%d] Pt.x %d, Pt.y %d\n", i, rPt.x,
rPt.y);<BR> }</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial
size=2> //--------------------------------------------------------=
-------------------------<BR> //
begin : A random-access iterator addressing the first element in the =
vector or
<BR> // to the =
location
succeeding an empty vector. You should always compare
<BR> // the value =
returned
with vector::end to ensure it is valid.<BR> //<BR> // end : A
random-access iterator to the end of the vector object. You should
<BR> // compare the value =
returned to
vector::begin to ensure it is
valid.<BR> //<BR> //-------------------------------------------=
--------------------------------------<BR> m_Pts.resize(20);<BR>&nbs=
p;std::vector<CPoint>::const_iterator
m_cIter;<BR> // *c1_cIter = 200; Error. c1_cIter is
constant.<BR> m_cIter = m_Pts.begin();<BR> TRACE("Position =
of
Iterator: %d\n", *m_cIter);</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial =
size=2> std::vector<CPoint>::iterator
m_Iter;<BR> m_Iter = m_Pts.begin();<BR> TRACE("Position of =
Iterator:
%d\n", *m_Iter);<BR> m_Iter = =
m_Pts.end();<BR> TRACE("Position of
Iterator: %d\n", *m_Iter);<BR> *m_Iter = =
10;<BR> TRACE("Position of
Iterator: %d\n", *m_Iter);</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2> for (UINT i = 0; i < =
m_Pts.size();
i++)<BR> {<BR> CPoint& rPt = m_Pts.at(i);<BR> =
TRACE("Pt[%d]
Pt.x %d, Pt.y %d\n", i, rPt.x, rPt.y);<BR> }</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2> for(m_Iter = m_Pts.begin(); =
m_Iter <
m_Pts.end(); m_Iter++)<BR> {<BR> CPoint& pt =
m_Pts.at(*m_Iter);<BR> TRACE("Pt[%d] Pt.x %d, Pt.y %d\n", pt.x,
pt.y);<BR> }<BR></FONT></DIV></BODY></HTML>
------=_NextPart_000_0017_01C77BE7.D5F789E0--