With the following:
#include <set>
std::set<const char *> global = std::set<const char *>();
void x() {
const char *c = "a";
const char *d = "b";
global.insert(c);
global.insert(d);
}
int main() {
x();
for (std::set<const char *>::const_iterator iter=global.begin(), end=global.end(); iter!=end; ++iter) {
printf("%s\n", *iter);
}
return 0;
}
In the end, as expected, I receive a
and b
printed.
Yet, is there any guarantee that, for example, if that set was part of a bozo
object, that as the set they'd last until the end of bozo
's lifetime? Or would I have to strdup
the strings to be sure?