Thread overview
Referencing the Standard Input Stream
Jun 17, 2002
Ryan Michel
Jun 18, 2002
Walter
Jun 18, 2002
Ryan Michel
Jun 18, 2002
Pavel Minayev
Jun 19, 2002
Ryan Michel
Jun 19, 2002
Pavel Minayev
June 17, 2002
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"


June 18, 2002
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"
>
>


June 18, 2002
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"
> >
> >
> 
> 



June 18, 2002
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?
June 19, 2002
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?



June 19, 2002
On Wed, 19 Jun 2002 07:34:51 GMT Ryan Michel <ryan@michel.com.au> wrote:

> 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++.

Aah! Download the new version from http://int19h.tamb.ru. Or wait till Walter
includes it into the official distribution (I hope). =)

> 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?

Standard streams are in fact just files attached to stdin, stdout, and strerr. You either need a new version to use them, or you have to create them manually:

	File stdin, stdout, stderr;

	extern(Windows) HANDLE GetStdHandle(uint nStdHandle);

	static this()
	{
		stdin = new File(GetStdHandle(-10));
		stdout = new File(GetStdHandle(-11));
		stderr = new File(GetStdHandle(-12));
	}

In the old version (present in Phobos), you could only use the read() functions
(which are binary), or the readLine() and readString(). However, in the new
version
you also get scanf(), the main feature of which is that it works with D strings:

	char[] s;
	stdin.scanf("%.*s", s);

I'm not aware of any other way to read a string directly into a dynamic char[]
array
so far.