Problems with MemoryStream

Jonathan M Davis jmdavisProg at gmx.com
Sun Jan 23 00:40:45 PST 2011


On Saturday 22 January 2011 14:32:18 Tobias Pankrath wrote:
> Hello,
> 
> I just got my hands on a copy of TDPL and I like the book and D is very
> promising. But I run into problems with the easiest of program. I just
> want to write to and from a stream, just the way it is possible with
> C++ stringstreams. But this program produces an empty line as
> output.
> 
> /** begin program
> import std.stdio;
> import std.stream;
> 
> void main() {
>   auto stream = new MemoryStream( );
>   string s = "this is a line";
> 
>   stream.writeLine(s);
>   char[] get = stream.readLine();
>   writeln(get);
> }
> 
> // end of program
> 
> Why? Whats the right way to do it?

std.stream is going to be completely replaced with a properly range-based, 
streaming solution. Work has been done on an API for its replacement, and the 
API was reveiwed on the D list fairly recently, but I don't know exactly what 
it's currrent status is. And once the API has been agreed upon, then the code  
has to be written. So, it'll likely be a few releases before std.stream gets 
replaced. So, in the long run, you're not going to want to be using std.stream 
(or at least the current std.stream - I don't know if the replacement will be a 
new module or if it's just that the functions currently there will be deprecated 
and  replaced with the new ones).

Now, that doesn't stop you from using it now if you want to. But personally, I 
only ever use std.stdio and std.file, so I'm not well versed in how to use 
std.stream. I just thought that I should point out that it's not sticking around 
in its current form long term.

- Jonathan M Davis


More information about the Digitalmars-d-learn mailing list