From: Brendan on
With vectors, you can take the address of the first element in order
to pass the underlying data to API's that take char*'s like so:

vector<char> v(BUF_SIZE);
// for some function: void write_to_buf(char* buf, size_t buf_len)
write_to_buf(&v[0], BUF_SIZE);

With std::strings I've always been leery of doing the same thing since
I know that some std::string implementations, gcc's in particular, are
Copy On Write. To make this safe, a COW string str would have to make
a copy when you do a str[index] if there is more than one reference to
the underlying string. Does the standard require this to be safe?

Thanks,
Brendan

--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]