Recently I needed to delete items from a sequence like a deque , list or vector from a for loop, I figured out that I have to do something like this:
for(iter = list.begin(); iter != list.end(); ++iter)
{
// your code
iter = list.erase(iter);
--iter;
// your code
}
It looks basic but it took me a while to figure it out so I wanted to share in case somebody need it.
Tags: deque, Erase, list, Loop, rem, Remove, vector
[code="php"]
< ?php
// Get a file into an array. In this example we'll go through HTTP to get
// the HTML source of a URL.
$lines = file('somefile.txt', FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
// Loop through our array, show HTML source as HTML source; and line numbers too.
foreach ($lines as $line_num => $line) {
echo "Line #{$line_num} : " . htmlspecialchars($line) . "
\n";
}
?>
[/code]
Tags: FILE IGNORE NEW LINES FILE SKIP EMPTY LINES, HTML, HTTP, Line, Loop, source, URL