www.digitalmars.com         C & C++   DMDScript  

D - Referencing the Standard Input Stream

reply Ryan Michel <ryan michel.com.au> writes:
I have written some functions from C++ stdin, cin.get, cin.getline, cin.ignore
but cannot access the standard 
input stream.  I have tried:
std.getline(aString, 255, '\n');
stdin.ignore(255, '\n');
Stream::get(aChar);

ryan
"If at first you don't succeed you must be a programmer"
Jun 07 2002
parent reply "Walter" <walter digitalmars.com> writes:
C++ functions and libraries are not directly accessible from D. You'll need
to provide a C wrapper for them. -Walter

"Ryan Michel" <ryan michel.com.au> wrote in message
news:1103_1023489176 news.digitalmars.com...
 I have written some functions from C++ stdin, cin.get, cin.getline,
cin.ignore but cannot access the standard
 input stream.  I have tried:
 std.getline(aString, 255, '\n');
 stdin.ignore(255, '\n');
 Stream::get(aChar);

 ryan
 "If at first you don't succeed you must be a programmer"
Jun 18 2002
parent reply Ryan Michel <ryan michel.com.au> writes:
I used some functions from the "stream.d" module found at DedicateD and wrote
functions that have the same 
functionality as these C++ functions.

ryan
"If at first you don't succeed you must be a programmer"

On Tue, 18 Jun 2002 00:47:07 -0700, "Walter" <walter digitalmars.com> wrote:
 C++ functions and libraries are not directly accessible from D. You'll need
 to provide a C wrapper for them. -Walter
 
 "Ryan Michel" <ryan michel.com.au> wrote in message
 news:1103_1023489176 news.digitalmars.com...
 I have written some functions from C++ stdin, cin.get, cin.getline,
cin.ignore but cannot access the standard
 input stream.  I have tried:
 std.getline(aString, 255, '\n');
 stdin.ignore(255, '\n');
 Stream::get(aChar);

 ryan
 "If at first you don't succeed you must be a programmer"
Jun 18 2002
parent reply Pavel Minayev <evilone omen.ru> writes:
On Tue, 18 Jun 2002 10:32:23 GMT Ryan Michel <ryan michel.com.au> wrote:

 I used some functions from the "stream.d" module found at DedicateD and 
wrote functions that have the same
 functionality as these C++ functions.
Just why would you need getline() and get() if they are already there? Also, did you make them part of the class?
Jun 18 2002
parent reply Ryan Michel <ryan michel.com.au> writes:
where are they?
at the moment only input function is scanf() that I know about and my
programming knowledge does not stretch to 
C just to C++.

Yes I did make them member functions of Stream that File, memory stream etc.
are derived from.

I can use:
File aFile = new File;
aFile.open("file.txt");

this stream (aFile) can be referenced but how to reference the standard input
stream (ie. from the keyboard)?

Does it have a buffer like the derived streams?

I am only familiar with C++ style ostream & istream classes and overloaded
stream insertion and stream 
extraction operators.

ryan

On Tue, 18 Jun 2002 16:09:48 +0400, Pavel Minayev <evilone omen.ru> wrote:
 On Tue, 18 Jun 2002 10:32:23 GMT Ryan Michel <ryan michel.com.au> wrote:
 
 I used some functions from the "stream.d" module found at DedicateD and 
wrote functions that have the same
 functionality as these C++ functions.
Just why would you need getline() and get() if they are already there? Also, did you make them part of the class?
Jun 19 2002
parent Pavel Minayev <evilone omen.ru> writes:
On Wed=2C 19 Jun 2002 07=3A34=3A51 GMT Ryan Michel
=3Cryan=40michel=2Ecom=2Eau=3E wrote=3A

=3E where are they=3F
=3E at the moment only input function is scanf=28=29 that I know about and my 
programming knowledge does not stretch to 
=3E C just to C++=2E

Aah! Download the new version from http=3A=2F=2Fint19h=2Etamb=2Eru=2E Or wait
till Walter
includes it into the official distribution =28I hope=29=2E =3D=29

=3E Yes I did make them member functions of Stream that File=2C memory stream
etc=2E 
are derived from=2E
=3E 
=3E I can use=3A
=3E File aFile =3D new File=3B
=3E aFile=2Eopen=28=22file=2Etxt=22=29=3B
=3E 
=3E this stream =28aFile=29 can be referenced but how to reference the standard 
input stream =28ie=2E from the keyboard=29=3F
=3E
=3E Does it have a buffer like the derived streams=3F

Standard streams are in fact just files attached to stdin=2C stdout=2C and
strerr=2E
You either need a new version to use them=2C or you have to create them
manually=3A

=09File stdin=2C stdout=2C stderr=3B

=09extern=28Windows=29 HANDLE GetStdHandle=28uint nStdHandle=29=3B

=09static this=28=29
=09{
=09=09stdin =3D new File=28GetStdHandle=28-10=29=29=3B
=09=09stdout =3D new File=28GetStdHandle=28-11=29=29=3B
=09=09stderr =3D new File=28GetStdHandle=28-12=29=29=3B
=09}

In the old version =28present in Phobos=29=2C you could only use the read=28=29
functions
=28which are binary=29=2C or the readLine=28=29 and readString=28=29=2E
However=2C in the new 
version
you also get scanf=28=29=2C the main feature of which is that it works with D
strings=3A

=09char=5B=5D s=3B
=09stdin=2Escanf=28=22%=2E*s=22=2C s=29=3B

I'm not aware of any other way to read a string directly into a dynamic
char=5B=5D 
array
so far=2E
 
Jun 19 2002