Does “&s[0]” point to contiguous characters in a std::string?
问题 I'm doing some maintenance work and ran across something like the following: std::string s; s.resize( strLength ); // strLength is a size_t with the length of a C string in it. memcpy( &s[0], str, strLength ); I know using &s[0] would be safe if it was a std::vector, but is this a safe use of std::string? 回答1: A std::string's allocation is not guaranteed to be contiguous under the C++98/03 standard, but C++11 forces it to be. In practice, neither I nor Herb Sutter know of an implementation