Thread overview
stdin.read
Sep 02, 2004
Ben Hinkle
September 02, 2004
This code:

////////////////
import std.stream;

void main ()
{
    int x;
    stdin.read(x);
}

////////////////

Produces "Error: not enough data in stream" when given some input. The same happens if x is ubyte, byte, ushort, short, uint, ulong, long, float, double, real, char []. It works ok if it's char or wchar. If it's wchar [], it produces an AV. Tested with dmd 0.101/Windows XP Pro.

-----------------------
Carlos Santander Bernal


September 02, 2004
Assuming you ran this at the console, did you hit return without typing anything in? As coded you have to type in 4 chars and those will fill in the int. If you want to take string input and parse it to get an integer try calling "scanf" instead of read. Call "read" when you have binary data.

If you want to experiment some more, try running:

import std.stream;

int main() {
int x;
stdout.writefln("type 1234 please");
stdin.read(x);
stdout.writefln("prints 49 50 51 52 right?");
stdout.writefln(x&0xFF," ",(x&0xFF00)>>8," ",
 (x&0xFF0000)>>16," ",(x&0xFF000000)>>24);
return 0;
}

and try typing in different things at the console.

"Carlos Santander B." <carlos8294@msn.com> wrote in message news:ch7ms5$ka5$1@digitaldaemon.com...
> This code:
>
> ////////////////
> import std.stream;
>
> void main ()
> {
>     int x;
>     stdin.read(x);
> }
>
> ////////////////
>
> Produces "Error: not enough data in stream" when given some input. The
same
> happens if x is ubyte, byte, ushort, short, uint, ulong, long, float,
double,
> real, char []. It works ok if it's char or wchar. If it's wchar [], it
produces
> an AV. Tested with dmd 0.101/Windows XP Pro.
>
> -----------------------
> Carlos Santander Bernal
>
>


September 02, 2004
"Ben Hinkle" <bhinkle@mathworks.com> escribió en el mensaje
news:ch7png$lgr$1@digitaldaemon.com
| Assuming you ran this at the console, did you hit return without typing
| anything in? As coded you have to type in 4 chars and those will fill in the
| int. If you want to take string input and parse it to get an integer try
| calling "scanf" instead of read. Call "read" when you have binary data.
|
| If you want to experiment some more, try running:
|
| import std.stream;
|
| int main() {
| int x;
| stdout.writefln("type 1234 please");
| stdin.read(x);
| stdout.writefln("prints 49 50 51 52 right?");
| stdout.writefln(x&0xFF," ",(x&0xFF00)>>8," ",
|  (x&0xFF0000)>>16," ",(x&0xFF000000)>>24);
| return 0;
| }
|
| and try typing in different things at the console.

I still feel there's a bug. And I'm sorry, but I think it worked before the way
I think it should (couldn't tell how long ago, though).
But thanks anyway.

-----------------------
Carlos Santander Bernal