11 Jul
2003
11 Jul
'03
07:51
On Friday 11 July 2003 07:09, Verdi March wrote:
Hi,
why does this following code fragment produce segfault? ========================================== #include <iostream> #include <algorithm> #include <vector> using namespace::std;
void fillVector(vector<string>& v);
int main() { vector<string> src; fillVector(src);
vector<string> dst;
The destination container must be big enough!
// ====>> The following copy() is the culprit <<==== copy(src.begin() + 1, src.end(), dst.begin());
Or use this: copy(src.begin() + 1, src.end(), back_inserter( dst));
return 0; }
void fillVector(vector<string>& v) { v.push_back("field_A"); v.push_back("field_B"); v.push_back("field_C"); }