string initialization question.

Steven Schveighoffer schveiguy at yahoo.com
Mon Aug 2 04:45:27 PDT 2010


On Sat, 31 Jul 2010 05:37:41 -0400, Jason Spencer <spencer8 at sbcglobal.net>  
wrote:

> == Quote from Steven Schveighoffer (schveiguy at yahoo.com)'s article
>> I was wrong, I looked through the runtime and did not find such a
> function.
>
> std.string has a repeat() function.  Try:
>
> import std.string;
>
> void main()
> {
>    string divider = repeat("-", 5);
>    writeln(divider);
> }

It doesn't do the right thing.  It allocates, then initializes, resulting  
in a double-initialization.

-Steve


More information about the Digitalmars-d-learn mailing list