Problems with MemoryStream

Ali Çehreli acehreli at yahoo.com
Mon Jan 24 08:18:24 PST 2011


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);

It appears that there is either a single read+write position, or writing 
also advances the read position. Add the following line here:

   stream.seek(0, SeekPos.Set);

>   char[] get = stream.readLine();
>   writeln(get);
> }
>  
> // end of program
> 
> Why? Whats the right way to do it?
> 
> Greetings, Tobias
>  

Ali


More information about the Digitalmars-d-learn mailing list