This topic has been archived. It cannot be replied.
-
工作学习 / IT技术讨论 / (C++)How to get object from vector one by one in a loop? thanks.
After I erase an element from a list,where the pointer will point to?
-wendywendy(wind);
2001-7-22
(#140905@0)
-
再详细点,第二个问题pointer是指哪一个?
-rock_jack(The Door);
2001-7-22
(#140951@0)
-
templateuse iterator:
vector<object>::iterator aIterator;
for (aIterator = aVector.begin();aIterator != aVector.end();aIterator++){
// loop
}
the statement to remove an element from a vector is:
aIterator2 = aVector.erase(aIterator1);
aIterator2 is an iterator which desigates the next available element.
-jfhuang(Zigzag);
2001-7-22
{324}
(#141106@0)
-
in my interview, a question is :what's wrongfor (aIterator = aVector.begin();aIterator != aVector.end())
{
if (aVector.get(aIterator )==0)
aIterator =aVector.erase(aIterator );
alterator++;
}
so, if the last element is 0,error ?I failed to answer this question
-wendywendy(wind);
2001-7-23
{238}
(#141715@0)
-
if alterator points to the last element, aVector.erase(aIterator ) will return end().So you have to check if alterator is at the end. Otherwise you will get an error. The modified code is as follows,
for (aIterator = aVector.begin();aIterator != aVector.end())
{
if (aVector.get(aIterator )==0)
aIterator =aVector.erase(aIterator );
if (aIterator != aVector.end()) alterator++;
}
-jfhuang(Zigzag);
2001-7-23
{312}
(#142228@0)
-
It seems that you are an expert in C++, could you please help me? Just some simple questions.Thank you!
-lynx(jane);
2001-7-23
{1584}
(#142238@0)
-
Several ways can be used to get the current time
-jfhuang(Zigzag);
2001-7-24
{679}
(#143677@0)
-
Thank you very much and I have sloved the problems.
-lynx(jane);
2001-7-24
(#143694@0)
-
There are several ways to get the current time
-jfhuang(Zigzag);
2001-7-24
{679}
(#143680@0)
-
good,good, thanks,thanks.
-qiuqiu(秋秋);
2001-7-23
(#142240@0)
-
thanks. u r so helpful
-wendywendy(wind);
2001-7-25
(#143834@0)