std.stream question

Chris Nicholson-Sauls ibisbasenji at gmail.com
Fri Aug 4 02:31:38 PDT 2006


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:
> 
... code here ...
> 
> 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
> identifier module stream.stdin
... etc ...
> 
> 
> Any ideas? I am using the latest dmd.exe and dmc linker tools, etc. I am 
> stumped...
> 
> regards,
> Rob 
> 

Well the answer is simple: the example is outdated.  Guess I know something I need to fix. 
  ^_^''  The following should be the way to do it with "modern" D.

##################################################
import std.cstream : din, dout ;
import std.string  : toupper   ;

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

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

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

   return 0;
}
##################################################

The 'std*' streams are no longer in module 'std.stream' as far as I know.  Their roles 
were usurped by module 'std.cstream' a little ways back, which defines them as instances 
of the class 'std.cstream.CFile:Stream' and with the names 'din', 'dout', and 'derr'.

-- Chris Nicholson-Sauls



More information about the Digitalmars-d-learn mailing list