string version of array

Andrea Fontana nospam at example.com
Tue Nov 14 08:16:16 UTC 2017


On Tuesday, 14 November 2017 at 07:56:06 UTC, rikki cattermole 
wrote:
> On 14/11/2017 7:54 AM, Tony wrote:
>> Is there an easy way to get the string representation of an 
>> array, as would be printed by writeln(), but captured in a 
>> string?
>
> struct Foo {
> 	int x;	
> }
>
> void main() {
> 	Foo[] data = [Foo(1), Foo(2), Foo(3)];
> 	
> 	import std.conv : text;
> 	import std.stdio;
> 	
> 	writeln(data.text);
> }
>
> ---
>
> [Foo(1), Foo(2), Foo(3)]

Why not

import std.conv : to;
writeln(data.to!string);

?


More information about the Digitalmars-d-learn mailing list