Win32 API's GetLogicalDriveStrings returns a buffer of C-strings which looks something like:
"C:\<NULL>D:\<NULL>E:\<NULL><NULL>"
. I wanted to return a vector of strings and thought about using an istream iterator:
std::vector< std::string > foo()
{
std::unique_ptr<char[]> buffer( new char[1024+1] );
buffer[1024] = '\0';
const auto length = GetLogicalDriveStrings( 1024, buffer.get() );
std::istringstream ss( std::string( buffer.get(), buffer.get()+length ) );
return std::vector< std::string >(
std::istream_iterator<std::string>( ss ),
std::istream_iterator<std::string>()
);
}
How ever this always returns a vector of size 1. I suppose istream_iterator considers its job done when he finds a null byte. Is there a way to do what I want to do?