small question about LIST stl...
My code looks something like this...
And i get en error when trying to use the erase command with the randomNums.end(); which makes sense.Code:#include <list> #include <iostream> using namespace std; void main() { list<int> randomNums; int number20 = 0; while( number20 < 5 ) { (number20++); randomNums.push_back((2*number20) + 1); randomNums.push_back(2*number20); } list<int>::iterator iter = randomNums.begin(); randomNums.erase(randomNums.end()); for( list<int>::iterator iter = randomNums.begin() ; iter != randomNums.end() ; iter++) { cout << (*iter) << endl; } }
>>>HOW CAN I ERASE THE LAST ELEMENT FROM THE LIST?
also when I try to erase using this code:
[code]
randomNums.erase(iter++);
[/coode]
it won't erase the second entry.
>>WHY DOES LIST FUNCTION LIKE THIS??




Reply With Quote