std.stream question

Derek derek at psyc.ward
Fri Aug 4 02:37:23 PDT 2006


On Fri, 4 Aug 2006 18:49:53 +1000, chojin wrote:

> Eck. I am about to pull my hair out. I've been using D for 3 days now and 
> can't even get text input on the console going. The first 2 were tied up 
> trying to find a usable decent IDE solution.... others ironing out senseless 
> bugs with no documentation... and I have a computer science degree! Anyway I 
> feel like I could have a big rant but I'll get to the point.
> 
> I can compile most things just fine, but due to lack of finding decent 
> documentation for scanf I switched over to streams, which seem MUCH nicer... 
> but whenever I try to use them I get errors.
> 
> Currently trying to use streams using this sample code I got from dsource:
> 
> import std.stream;
> import std.string;
> 
> int main()
> {
>     char[] input;
>     char[] output;
> 
>     // Ask for a string
>     std.stream.stdout.writeLine("Converts a lowercase string to 
> uppercase.");
>     std.stream.stdout.writeLine("Please enter a string:");
>     input = std.stream.stdin.readLine();
> 
>     // Convert to upper and print it
>     output = input.toupper();
>     std.stream.stdout.writeLine(output);
> 
>     return 0;
> }
> 
> And consistently, when using build.exe or dmake or dmd or whatever, I 
> recieve this output:
> 
> dmd.exe 
> C:\Homes\Administrator\Desktop\D\tester\stringtest.d -debug -g -c -unittest  
> -w -version=OLE_COM
> 
> C:\Homes\Administrator\Desktop\D\tester\stringtest.d(10): undefined 
> identifier module stream.stdout
> C:\Homes\Administrator\Desktop\D\tester\stringtest.d(10): undefined 
> identifier module stream.stdout
> C:\Homes\Administrator\Desktop\D\tester\stringtest.d(10): no property 
> 'writeLine' for type 'void'
> C:\Homes\Administrator\Desktop\D\tester\stringtest.d(10): function expected 
> before (), not 1 of type int
> C:\Homes\Administrator\Desktop\D\tester\stringtest.d(11): undefined 
> identifier module stream.stdout
> C:\Homes\Administrator\Desktop\D\tester\stringtest.d(11): undefined 
> identifier module stream.stdout
> C:\Homes\Administrator\Desktop\D\tester\stringtest.d(11): no property 
> 'writeLine' for type 'void'
> C:\Homes\Administrator\Desktop\D\tester\stringtest.d(11): function expected 
> before (), not 1 of type int
> C:\Homes\Administrator\Desktop\D\tester\stringtest.d(12): undefined 
> identifier module stream.stdin
> C:\Homes\Administrator\Desktop\D\tester\stringtest.d(12): undefined 
> identifier module stream.stdin
> 
> Any ideas? I am using the latest dmd.exe and dmc linker tools, etc. I am 
> stumped...
> 
> regards,
> Rob

When working with stdin/stdou/stderr you need to use the std.cstream
module...

import std.cstream;
import std.string;

int main()
{
    char[] input;
    char[] output;

    // Ask for a string
    std.cstream.dout.writeLine("Converts a lowercase string to
uppercase.");
    std.cstream.dout.writeLine("Please enter a string:");
    input = std.cstream.din.readLine();

    // Convert to upper and print it
    output = input.toupper();
    std.cstream.dout.writeLine(output);

    return 0;
}


---- Here is the output I get...

c:\temp>type test.d
import std.cstream;
import std.string;

int main()
{
    char[] input;
    char[] output;

    // Ask for a string
    std.cstream.dout.writeLine("Converts a lowercase string to
uppercase.");
    std.cstream.dout.writeLine("Please enter a string:");
    input = std.cstream.din.readLine();

    // Convert to upper and print it
    output = input.toupper();
    std.cstream.dout.writeLine(output);

    return 0;
}
c:\temp>build test
Path and Version : z:\util\build.exe v3.02(2207)
  built on Sat Jun 24 00:44:57 2006

c:\temp>test
Converts a lowercase string to uppercase.
Please enter a string:
kajshdkjhaksdjhakjshdkja
KAJSHDKJHAKSDJHAKJSHDKJA

c:\temp>



-- 
Derek Parnell
Melbourne, Australia
"Down with mediocrity!"



More information about the Digitalmars-d-learn mailing list