...
Code Block |
---|
char input[] = "bogus@addr.com; cat /etc/passwd";
string::iterator loc;
string email;
// copy into string converting ";" to " "
for (size_t i=0; i <= strlen(input); i++) {
if (input[i] != ';') {
loc = email.insert(loc, input[i]);
}
else {
loc = email.insert(loc, ' ');
}
++loc;
} // end string for each element in NTBS
|
Non-Compliant Example
Code Block |
---|
...
The intent of these iterator invalidation rules is to give implementors greater freedom in implementation techniques. Some implementations implement method version that do not invalidate references, pointers, and iterators in all cases. Check with your implementation specific documentation and document any violation of the semantics specified by the standard for portability.
References
- Meyers 01 Item 43: Prefer algorithm calls to hand-written loops.
- ISO/IEC 14882-2003 21.3 Class template basic_string