www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Command Line Input

reply Shom <Shom_member pathlink.com> writes:
Hi Everyone,

I just started messing around with D... and it totally kicks butt!
However, is there any easy way for command line input? I mean something simple
like the good old C/C++ cin >>

I would appreciate any help with this.

Thanks,

Shom
May 11 2005
next sibling parent reply Hasan Aljudy <hasan.aljudy gmail.com> writes:
Shom wrote:
 Hi Everyone,
 
 I just started messing around with D... and it totally kicks butt!
 However, is there any easy way for command line input? I mean something simple
 like the good old C/C++ cin >>
 
 I would appreciate any help with this.
 
 Thanks,
 
 Shom
 
 

I'm new myself. cin >> is a C++ thing, for now, D is stuck with the old C way, which is scanf(...); It would be nice if there was a cleaner way to do this (someone could write some sort of a wrapper?)
May 11 2005
parent reply =?ISO-8859-1?Q?Anders_F_Bj=F6rklund?= <afb algonet.se> writes:
Hasan Aljudy wrote:

 I just started messing around with D... and it totally kicks butt!
 However, is there any easy way for command line input? I mean 
 something simple
 like the good old C/C++ cin >>

 I would appreciate any help with this.

I'm new myself. cin >> is a C++ thing, for now, D is stuck with the old C way, which is scanf(...); It would be nice if there was a cleaner way to do this (someone could write some sort of a wrapper?)

You mean std.stdio.readf, which hasn't been added to DMD just yet... ("readf" is to "writef", what "scanf" is to "printf". i.e. the D way) See digitalmars.D/21692 You should also check out the Mango Tree, which has stream classes. (unfortunately Dsource is down at the moment, but when it comes back) --anders
May 12 2005
parent reply John Reimer <brk_6502 yahoo.com> writes:
Anders F Björklund wrote:
 Hasan Aljudy wrote:
 
 I just started messing around with D... and it totally kicks butt!
 However, is there any easy way for command line input? I mean 
 something simple
 like the good old C/C++ cin >>

 I would appreciate any help with this.

I'm new myself. cin >> is a C++ thing, for now, D is stuck with the old C way, which is scanf(...); It would be nice if there was a cleaner way to do this (someone could write some sort of a wrapper?)

You mean std.stdio.readf, which hasn't been added to DMD just yet... ("readf" is to "writef", what "scanf" is to "printf". i.e. the D way) See digitalmars.D/21692 You should also check out the Mango Tree, which has stream classes. (unfortunately Dsource is down at the moment, but when it comes back) --anders

Indeed. Check Mango out. :-) Anders, Just looking at your example in your news link above: read(&name); // without format readf("%s", &name); // with format I was curious to know why you chose to use the "address of" operator here. Wouldn't it be better to use d's inout reference instead? That ampersand is just as unattractive now in D as it has been in C for all these years. I could be missing something, though. -JJR
May 12 2005
next sibling parent =?ISO-8859-1?Q?Anders_F_Bj=F6rklund?= <afb algonet.se> writes:
John Reimer wrote:

 Just looking at your example in your news link above:
 
 read(&name); // without format
 readf("%s", &name); // with format
 
 I was curious to know why you chose to use the "address of" operator 
 here.  Wouldn't it be better to use d's inout reference instead?  That 
 ampersand is just as unattractive now in D as it has been in C for all 
 these years.  I could be missing something, though.

variadic inout is not allowed ? Besides, using pointers make it easier to separate the format strings and the string receptors... (since there is no "const char *" and "char *" distinction in D) Unfortunately it doesn't work very good, since TypeInfo for pointers is not implemented yet. So it relies on some horrible workarounds now. But when typeid for pointers works, it's simple to remove those... readf is just intended as a improvement over scanf. Not a cure-all ? (besides it seemed silly to have a "stdio" that only did O and not I) Just as writef is an improvement over printf, but still somewhat ugly. (but I think my new write/writeln addition fixes that, to some degree) --anders
May 12 2005
prev sibling parent =?ISO-8859-1?Q?Anders_F_Bj=F6rklund?= <afb algonet.se> writes:
John Reimer wrote:

 You should also check out the Mango Tree, which has stream classes.
 (unfortunately Dsource is down at the moment, but when it comes back)

Indeed. Check Mango out. :-)

Maybe I forgot to mention it, but Mango doesn't work on Mac OS X (yet). Whileas scanf and readf (with some workarounds) do. That's it, for me. --anders
May 12 2005
prev sibling parent reply SeeSchloss <SeeSchloss_member pathlink.com> writes:
In article <d5uspi$2gsg$1 digitaldaemon.com>, Shom says...
Hi Everyone,

I just started messing around with D... and it totally kicks butt!
However, is there any easy way for command line input? I mean something simple
like the good old C/C++ cin >>

I would appreciate any help with this.

Hmm, well I'm not sure how cin >> works, but std.stream.stdin.readLine () is nice for reading stdin. BTW, it'd be nice if importing std.stream didn't import some other std.c.<something ?> package which already defines std{in,out,err} as it requires to make an alias if one wants to simply use "stdin" instead of "std.stream.stdin".
May 12 2005
parent reply "Ben Hinkle" <ben.hinkle gmail.com> writes:
"SeeSchloss" <SeeSchloss_member pathlink.com> wrote in message 
news:d5v8mi$2u6a$1 digitaldaemon.com...
 In article <d5uspi$2gsg$1 digitaldaemon.com>, Shom says...
Hi Everyone,

I just started messing around with D... and it totally kicks butt!
However, is there any easy way for command line input? I mean something 
simple
like the good old C/C++ cin >>

I would appreciate any help with this.

Hmm, well I'm not sure how cin >> works, but std.stream.stdin.readLine () is nice for reading stdin. BTW, it'd be nice if importing std.stream didn't import some other std.c.<something ?> package which already defines std{in,out,err} as it requires to make an alias if one wants to simply use "stdin" instead of "std.stream.stdin".

That should work. For example import std.stream; int main() { char[] line = stdin.readLine(); stdout.writefln("%s",line); return 0; } Is that what you mean?
May 12 2005
parent reply SeeSchloss <SeeSchloss_member pathlink.com> writes:
 BTW, it'd be nice if importing std.stream didn't import some other
 std.c.<something ?> package which already defines std{in,out,err} as it 
 requires
 to make an alias if one wants to simply use "stdin" instead of
 "std.stream.stdin".

That should work. For example import std.stream; int main() { char[] line = stdin.readLine(); stdout.writefln("%s",line); return 0; } Is that what you mean?

Yeah, that's what I mean. And... ok I was just wrong, it's importing both std.stream and std.stdio, which creates a conflict. I guess I never imported std.stream without std.stdio, and since it happened just when adding the std.stream import, I never looked anywhere else. *hides in shame*
May 12 2005
parent "Ben Hinkle" <ben.hinkle gmail.com> writes:
"SeeSchloss" <SeeSchloss_member pathlink.com> wrote in message 
news:d5vt5l$emj$1 digitaldaemon.com...
 BTW, it'd be nice if importing std.stream didn't import some other
 std.c.<something ?> package which already defines std{in,out,err} as it
 requires
 to make an alias if one wants to simply use "stdin" instead of
 "std.stream.stdin".

That should work. For example import std.stream; int main() { char[] line = stdin.readLine(); stdout.writefln("%s",line); return 0; } Is that what you mean?

Yeah, that's what I mean. And... ok I was just wrong, it's importing both std.stream and std.stdio, which creates a conflict. I guess I never imported std.stream without std.stdio, and since it happened just when adding the std.stream import, I never looked anywhere else. *hides in shame*

I agree it's annoying to have std.stdio and std.stream conflict. Maybe std.stream.stdin and friends need a rename...
May 12 2005