How to convert a string command line argument to an int?

MoonlightSentinel moonlightsentinel at disroot.org
Thu Mar 3 07:50:54 UTC 2022


On Thursday, 3 March 2022 at 07:32:24 UTC, BoQsc wrote:
> I tried to use `std.conv.parse(args[2])`,
> [...]
> But I'm getting this error

The code doesn't declare the type to be parsed, use 
`parse!uint(...)`.

But `to!uint` seems more appropriate for your code because 
`parse` ignores non-number characters after the number, e.g.

```d
void main()
{
     string input = "123abc";
     writeln(parse!uint(input)); // 123
}
```


More information about the Digitalmars-d-learn mailing list