I've a strange error: I want to copy the content of an ostringstream into a vecotr of unsigned chars:

```
vector< uint8_t > buffer;
ostringstream os;
os << num1 << char1 << num2 << char2;

// 1. this will crash
buffer.insert( buffer.end(), os.str().begin(), os.str().end() );

// 2. this also crash
copy( os.str().begin(), os.str().end(), back_inserter( buffer );

string str = os.str();

// 4. this work 
buffer.insert( buffer.end(), str().begin(), str().end() );

// 5. this also works
copy( str().begin(), tr().end(), back_inserter( buffer );

```

I can't understand why 1 and 2 crash on visual studio 2010. 

Does someone has some suggest?

 **EDIT** 

 The solution is: 

```
vector< uint8_t > buffer;
ostringstream os;
os << num1 << char1 << num2 << char2;

const string& str = os.str();

// 4. this work 
buffer.insert( buffer.end(), str().begin(), str().end() );

```