Can I output strings using core.stdc.stdio?

drug drug2004 at bk.ru
Wed Dec 23 13:06:37 UTC 2020


On 12/23/20 3:23 PM, Godnyx wrote:
> 
> Any ideas?

Just fix your typos:

```D
import std : printf, toStringz;

void put(A...)(string prompt, A args) {
     static foreach (ulong i; 0..args.length) {
         static if (is(typeof(args[i]) == string))
             printf("%s\n", args[i].toStringz);
         static if (is(typeof(args[i]) == int))
             printf("%i\n", args[i]);
         static if (is(typeof(args[i]) == bool)) {
             if (args[i])
                 printf("true");
             else
                 printf("false");
         }
     }
}

void main() {
     put("Prompt:", "Hello, my age is: ", 19, true);
}
```

P.S. replace `arg` by `args[i]`



More information about the Digitalmars-d-learn mailing list