Been wondering about this one...

I need to copy a std::string into a vector<TCHAR> (many times) and I'm looking at the most efficient way to do so.

Code:
vec.assign( str.begin(), str.end() );
is insufficient as that doesn't guarantee the zero terminator.

Code:
vec.assign( str.begin(), str.end() );
vec.push_back( _T('\0') );
works but can cause a reallocation (=bad).

Code:
vec.reserve( str.size()+1 );
vec.assign( str.begin(), str.end() );
vec.push_back( _T('\0') );
solves the reallocation, but adds quite a bit of unneeded bulk.
there's an unnecessary size check in assign() as well as in the push_back now.

is this the only thing I can do, or is there a better solution that does: reserve size+1, copy size bytes from string to vector, set terminator. without any excess ?