digitalmars.D.learn - Problems with MemoryStream
- Tobias Pankrath (22/22) Jan 22 2011 Hello,
- Jonathan M Davis (15/39) Jan 23 2011 std.stream is going to be completely replaced with a properly range-base...
- =?UTF-8?B?QWxpIMOHZWhyZWxp?= (5/32) Jan 24 2011 It appears that there is either a single read+write position, or writing...
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? Greetings, Tobias
Jan 22 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
Jan 23 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, TobiasAli
Jan 24 2011