11 Jul
2003
11 Jul
'03
07:25
Verdi March wrote:
why does this following code fragment produce segfault?
vector<string> dst;
// ====>> The following copy() is the culprit <<==== copy(src.begin() + 1, src.end(), dst.begin());
In this case you would need vector<string> dst( src.end() - src.begin() + 1 ); to ensure that there are elements to overwrite. copy doesn't use, for example, push_back() if there isn't space to copy to. Hence the segfault. Come to think of it, this makes copy poor for reading input streams because there's nothing to prevent buffer overrun. -- JDL Non enim propter gloriam, diuicias aut honores pugnamus set propter libertatem solummodo quam Nemo bonus nisi simul cum vita amittit.