1

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?

qdii
  • 12,505
  • 10
  • 59
  • 116
  • 1
    I've tried to reduce your problem to a [program](http://coliru.stacked-crooked.com/a/ff871e9d9a8bb642) that doesn't require the Windows API. Can you confirm this is the problem you're experiencing? –  Nov 05 '14 at 13:29

0 Answers0