digitalmars.D.learn - readf?
- Fredrik Olsson (9/9) Oct 12 2005 At http://www.algonet.se/~afb/d/stdio/ in stdio.d, Anders F Björklund
- Ben Hinkle (4/13) Oct 12 2005 check out http://www.digitalmars.com/d/phobos/std_stream.html. The strea...
- Ivan Senji (4/7) Oct 12 2005 I was wondering today why din is in std.cstream and not int std.stream
- Deewiant (2/11) Oct 12 2005 There is no need, std.cstream publically imports std.stream.
- Ivan Senji (5/20) Oct 12 2005 Maybe this doesn't make sense, but i don't need cstream's CFile only
- Ben Hinkle (6/26) Oct 12 2005 std.cstream also publically imports std.c.stdio. The reason for making
- Ivan Senji (11/25) Oct 12 2005 Most of what you say makes sense and i understand it but not the last
- Ben Hinkle (6/33) Oct 13 2005 The OS equivalents to stdin are GetStdHandle(STD_INPUT_HANDLE) on Window...
- Sean Kelly (19/22) Oct 12 2005 When I originally wrote readf I held off on submitting it because TypeIn...
- Sean Kelly (5/9) Oct 12 2005 I just checked std.stream and it looks like readf has been fully rewritt...
- =?ISO-8859-1?Q?Anders_F_Bj=F6rklund?= (14/37) Nov 08 2005 I'm pretty happy with how the *syntax* turned out, but not the
- Sean Kelly (8/28) Nov 08 2005 Yeah you pretty much have to use pointers, as varargs don't allow you to...
- =?utf-8?B?RGF3aWQgQ2nEmcW8YXJraWV3aWN6?= (7/14) Oct 18 2005 One more question.
- =?UTF-8?B?SmFyaS1NYXR0aSBNw6RrZWzDpA==?= (17/35) Oct 18 2005 I recommend modern programming with exceptions:
- =?utf-8?B?RGF3aWQgQ2nEmcW8YXJraWV3aWN6?= (9/28) Oct 21 2005 Emm ... where is any form of "read" "scan" or something actually? I'm
At http://www.algonet.se/~afb/d/stdio/ in stdio.d, Anders F Björklund have a a stdio with readf functions. Is there a reason that these are not present in the official Phobos? And what is the preferred way to read stuff from the keyboard? Writef/writefln is a superb mix of the powers of Pascal's write and writeln combined with C's printf. There should be an equally powerful way to read data, should there not? regards Fredrik Olsson
Oct 12 2005
"Fredrik Olsson" <peylow gmail.com> wrote in message news:dij444$1c93$1 digitaldaemon.com...At http://www.algonet.se/~afb/d/stdio/ in stdio.d, Anders F Björklund have a a stdio with readf functions. Is there a reason that these are not present in the official Phobos? And what is the preferred way to read stuff from the keyboard? Writef/writefln is a superb mix of the powers of Pascal's write and writeln combined with C's printf. There should be an equally powerful way to read data, should there not? regards Fredrik Olssoncheck out http://www.digitalmars.com/d/phobos/std_stream.html. The stream wrapper for stdin is std.cstream.din.
Oct 12 2005
Ben Hinkle wrote:check out http://www.digitalmars.com/d/phobos/std_stream.html. The stream wrapper for stdin is std.cstream.din.I was wondering today why din is in std.cstream and not int std.stream where it would IMO be better to be? If i wan't to use streams and din why the need to import both stream and cstream?
Oct 12 2005
Ivan Senji wrote:Ben Hinkle wrote:There is no need, std.cstream publically imports std.stream.check out http://www.digitalmars.com/d/phobos/std_stream.html. The stream wrapper for stdin is std.cstream.din.I was wondering today why din is in std.cstream and not int std.stream where it would IMO be better to be? If i wan't to use streams and din why the need to import both stream and cstream?
Oct 12 2005
Deewiant wrote:Ivan Senji wrote:Maybe this doesn't make sense, but i don't need cstream's CFile only din/dout, so i would like not to have to import cstream. Now that i think about it is there any reason why CFile is not in std.stream? If there is i can't see it.Ben Hinkle wrote:There is no need, std.cstream publically imports std.stream.check out http://www.digitalmars.com/d/phobos/std_stream.html. The stream wrapper for stdin is std.cstream.din.I was wondering today why din is in std.cstream and not int std.stream where it would IMO be better to be? If i wan't to use streams and din why the need to import both stream and cstream?
Oct 12 2005
"Ivan Senji" <ivan.senji_REMOVE_ _THIS__gmail.com> wrote in message news:dijt1a$2bqk$1 digitaldaemon.com...Deewiant wrote:std.cstream also publically imports std.c.stdio. The reason for making cstream was because 1) std.stream is already big and 2) cstream is for the C library wrappers and users should be aware of when they are wrapping the C stdin/out etc instead of using the native OS interface to console io.Ivan Senji wrote:Maybe this doesn't make sense, but i don't need cstream's CFile only din/dout, so i would like not to have to import cstream. Now that i think about it is there any reason why CFile is not in std.stream? If there is i can't see it.Ben Hinkle wrote:There is no need, std.cstream publically imports std.stream.check out http://www.digitalmars.com/d/phobos/std_stream.html. The stream wrapper for stdin is std.cstream.din.I was wondering today why din is in std.cstream and not int std.stream where it would IMO be better to be? If i wan't to use streams and din why the need to import both stream and cstream?
Oct 12 2005
Ben Hinkle wrote:"Ivan Senji" <ivan.senji_REMOVE_ _THIS__gmail.com> wrote in message news:dijt1a$2bqk$1 digitaldaemon.com...Most of what you say makes sense and i understand it but not the last part about wraping stdin/out vs. OS interface to console io? My class has toStream(Stream s) method and sometimes i would like it to output to console and sometimes to memory or file stream, sometimes i need obj.toStream(dout) or obj.toStream(memoryStream) ... And i don't like importing std.cstream because i do not need the std.c.stdio stuff it publically imports but only din and dout Streams. Aren't din/dout same as c++ cin/cout? I am trying to use them the same way. And i don't think stream's size (~80kB) would incresase that much if cstream (~4kB) was included :)Maybe this doesn't make sense, but i don't need cstream's CFile only din/dout, so i would like not to have to import cstream. Now that i think about it is there any reason why CFile is not in std.stream? If there is i can't see it.std.cstream also publically imports std.c.stdio. The reason for making cstream was because 1) std.stream is already big and 2) cstream is for the C library wrappers and users should be aware of when they are wrapping the C stdin/out etc instead of using the native OS interface to console io.
Oct 12 2005
"Ivan Senji" <ivan.senji_REMOVE_ _THIS__gmail.com> wrote in message news:dikvs5$1o02$1 digitaldaemon.com...Ben Hinkle wrote:The OS equivalents to stdin are GetStdHandle(STD_INPUT_HANDLE) on Windows and .. I forget... something like STDIN_FILENO on Linux."Ivan Senji" <ivan.senji_REMOVE_ _THIS__gmail.com> wrote in message news:dijt1a$2bqk$1 digitaldaemon.com...Most of what you say makes sense and i understand it but not the last part about wraping stdin/out vs. OS interface to console io?Maybe this doesn't make sense, but i don't need cstream's CFile only din/dout, so i would like not to have to import cstream. Now that i think about it is there any reason why CFile is not in std.stream? If there is i can't see it.std.cstream also publically imports std.c.stdio. The reason for making cstream was because 1) std.stream is already big and 2) cstream is for the C library wrappers and users should be aware of when they are wrapping the C stdin/out etc instead of using the native OS interface to console io.My class has toStream(Stream s) method and sometimes i would like it to output to console and sometimes to memory or file stream, sometimes i need obj.toStream(dout) or obj.toStream(memoryStream) ... And i don't like importing std.cstream because i do not need the std.c.stdio stuff it publically imports but only din and dout Streams.sure. din/dout could be declared in std.stream as simple Stream objects and initialized in std.cstream as CFiles.Aren't din/dout same as c++ cin/cout? I am trying to use them the same way. And i don't think stream's size (~80kB) would incresase that much if cstream (~4kB) was included :)
Oct 13 2005
In article <dij444$1c93$1 digitaldaemon.com>, Fredrik Olsson says...At http://www.algonet.se/~afb/d/stdio/ in stdio.d, Anders F Björklund have a a stdio with readf functions. Is there a reason that these are not present in the official Phobos?When I originally wrote readf I held off on submitting it because TypeInfo for pointers was basically broken. As a result, my code contained a workaround to determine the parameter types, and I didn't feel comfortable submitting a work in progress (readf also relies on changed to std.utf so data can be translated as it is read, so the submission would requiring changing that module as well). Anders later patched my readf to work on GDC (if I remember correctly) and it's been in that state ever since. Personally, I would like to see readf added to Phobos, but as I'm not using Phobos anyway, I haven't pushed for it. Also, as Ben Hinkle has mentioned, the stream classes offer a reasonable alternative for formatted input. I'm fairly certain the readf/scanf functionality isn't as complete as the version I wrote (mine is fully C99 compliant while the std.stream version was an abbreviated implementation way back when I last checked), but it should do for most purposes. And Mango is obviously another option. For what it's worth, my original implementation of readf is available here as "stdio addon": http://www.home.f4.ca/sean/d/ Sean
Oct 12 2005
In article <dik142$2jrn$1 digitaldaemon.com>, Sean Kelly says...I'm fairly certain the readf/scanf functionality isn't as complete as the version I wrote (mine is fully C99 compliant while the std.stream version was an abbreviated implementation way back when I last checked), but it should do for most purposes.I just checked std.stream and it looks like readf has been fully rewritten. I don't know if it covers all the subtleties of the scanf spec, but at a glance it seems a darn sight better than it used to be. Sean
Oct 12 2005
Sean Kelly wrote:I'm pretty happy with how the *syntax* turned out, but not the implementation - mostly due to the aforementioned TypeInfo bugs. Since it's using pointers (yes!, by design) it needs typeid for that to return sane results and it didn't so I just hacked it... Passing "mangle" characters around, and who knows what else :-PAt http://www.algonet.se/~afb/d/stdio/ in stdio.d, Anders F Björklund have a a stdio with readf functions. Is there a reason that these are not present in the official Phobos?When I originally wrote readf I held off on submitting it because TypeInfo for pointers was basically broken. As a result, my code contained a workaround to determine the parameter types, and I didn't feel comfortable submitting a work in progress (readf also relies on changed to std.utf so data can be translated as it is read, so the submission would requiring changing that module as well). Anders later patched my readf to work on GDC (if I remember correctly) and it's been in that state ever since.Personally, I would like to see readf added to Phobos, but as I'm not using Phobos anyway, I haven't pushed for it. Also, as Ben Hinkle has mentioned, the stream classes offer a reasonable alternative for formatted input. I'm fairly certain the readf/scanf functionality isn't as complete as the version I wrote (mine is fully C99 compliant while the std.stream version was an abbreviated implementation way back when I last checked), but it should do for most purposes. And Mango is obviously another option.I think most people turned to the various "stream" classes instead... Or just the std.c.stdio, with printf and scanf instead of std.stdio. Might take another look at it, like right after "D 1.0" is released :-) Meanwhile, Sir Writef is fighting all the windmills to find Ms Readf...For what it's worth, my original implementation of readf is available here as "stdio addon": http://www.home.f4.ca/sean/d/Thanks, I should have linked to that in a README or something ? I do believe I did so in the original posting to the newsgroup: http://www.digitalmars.com/d/archives/digitalmars/D/21692.html --anders
Nov 08 2005
Anders F Björklund wrote:I'm pretty happy with how the *syntax* turned out, but not the implementation - mostly due to the aforementioned TypeInfo bugs. Since it's using pointers (yes!, by design) it needs typeid for that to return sane results and it didn't so I just hacked it...Yeah you pretty much have to use pointers, as varargs don't allow you to specify 'out' parameters :) But with the type safety in D, the user would have to work pretty hard to screw something up anyway.Might take another look at it, like right after "D 1.0" is released :-) Meanwhile, Sir Writef is fighting all the windmills to find Ms Readf...It would be nice, but I'm devoting most of my nonexistent free time to Ares. I'm not planning to look at readf any time soon either.I think you did. SeanFor what it's worth, my original implementation of readf is available here as "stdio addon": http://www.home.f4.ca/sean/d/Thanks, I should have linked to that in a README or something ? I do believe I did so in the original posting to the newsgroup: http://www.digitalmars.com/d/archives/digitalmars/D/21692.html
Nov 08 2005
On Wed, 12 Oct 2005 15:46:43 +0200, Fredrik Olsson <peylow gmail.com> wrote:At http://www.algonet.se/~afb/d/stdio/ in stdio.d, Anders F Björklund have a a stdio with readf functions. Is there a reason that these are not present in the official Phobos? And what is the preferred way to read stuff from the keyboard? Writef/writefln is a superb mix of the powers of Pascal's write and writeln combined with C's printf. There should be an equally powerful way to read data, should there not?One more question. What are the functions to read int and to know if dumb user didn't entered garbages? I would like an exception, but flag would be sufficient too. -- Dawid Ciężarkiewicz
Oct 18 2005
Dawid Ciężarkiewicz wrote:On Wed, 12 Oct 2005 15:46:43 +0200, Fredrik Olsson <peylow gmail.com> wrote:I recommend modern programming with exceptions: import std.conv, std.stdio; void main() { char[] s = "123"; int i; try { i = toInt(s); } catch (ConvError e) { writefln("Bad input!"); } catch (ConvOverflowError e) { writefln("Overflow!"); } writefln("Got %d.", i); }At http://www.algonet.se/~afb/d/stdio/ in stdio.d, Anders F Björklund have a a stdio with readf functions. Is there a reason that these are not present in the official Phobos? And what is the preferred way to read stuff from the keyboard? Writef/writefln is a superb mix of the powers of Pascal's write and writeln combined with C's printf. There should be an equally powerful way to read data, should there not?One more question. What are the functions to read int and to know if dumb user didn't entered garbages? I would like an exception, but flag would be sufficient too.
Oct 18 2005
On Wed, 19 Oct 2005 01:10:51 +0200, Jari-Matti Mäkelä <jmjmak invalid_utu.fi> wrote:Emm ... where is any form of "read" "scan" or something actually? I'm looking for standard functions (to read for example int) that throw Exceptions on mistyped input. I know how to use Exceptions. <g> ;-) (You probably misunderstood me. || I haven't make myself clear.) Regards, -- Dawid CiężarkiewiczWhat are the functions to read int and to know if dumb user didn't entered garbages? I would like an exception, but flag would be sufficient too.I recommend modern programming with exceptions: import std.conv, std.stdio; void main() { char[] s = "123"; int i; try { i = toInt(s); } catch (ConvError e) { writefln("Bad input!"); } catch (ConvOverflowError e) { writefln("Overflow!"); } writefln("Got %d.", i); }
Oct 21 2005