noob Q: declaring string variables

Jesse Phillips jessekphillips+D at gmail.com
Sun May 30 12:24:27 PDT 2010


Duke Normandin wrote:

> Back again...
>
> As an introductory tutorial, I'm now using:
>
> http://www.dsource.org/projects/tutorials/wiki/InitializingVariablesExample
>
> BTW, somebody fix that page - the `writefln' statements are missing
> the %d and %s.
>
> char[] password = "sesame";
>
> didn't work on my MacOS X box. Why?
>
> [sidebar]
> Why is every D tutorial I've touched upon so far, been frigged up?
> This is NOT good advocacy, people! Bad advertising! Where is the good
> stuff hiding? L8r...
>


Almost all tutorials have been written for D1.x and most of those
probably in the early years. I suggest you sign up for an account and
modify the examples that give you problems.

For writefln, I believe D1.x did not reqire a %s (also writeln didn't
exist). And for this example %s for both would be perfectly fine and the
correct method.

The issue with char[] password = "sesame"; is what has already been
said. Both of these forms will work in D1.x and D2.x

auto password = "sesame";
string password = "sesame";

D1.x has an alias for string to char[] and D2.x has an alias to
immutable(char)[]

Important changes from 1.x to 2.x are found on this page:
http://digitalmars.com/d/2.0/features2.html

Another issues you might run into for the examples are 'inout'
parameters ('ref' works in both versions) 


More information about the Digitalmars-d-learn mailing list