d strings are the bane of my existance

Chris Katko ckatko at gmail.com
Sun Dec 5 16:24:34 UTC 2021


All I want:

```d
string ip_address = "192.168.1.1";
auto x = new InternetAddress( ip_string, "8008");
```

```d
source/app.d(161,16): Error: none of the overloads of `this` are 
callable using argument types `(string, int)`
/usr/include/dmd/phobos/std/socket.d(1472,5):        Candidates 
are: `std.socket.InternetAddress.this()`
/usr/include/dmd/phobos/std/socket.d(1519,5):                     
    `std.socket.InternetAddress.this(scope const(char)[] addr, 
ushort port)`
/usr/include/dmd/phobos/std/socket.d(1542,5):                     
    `std.socket.InternetAddress.this(uint addr, ushort port)`
/usr/include/dmd/phobos/std/socket.d(1550,5):                     
    `std.socket.InternetAddress.this(ushort port)`
/usr/include/dmd/phobos/std/socket.d(1562,5):                     
    `std.socket.InternetAddress.this(sockaddr_in addr)`
```

So InternetAddress cannot be constructed with a string. Only a 
const(char)[]. But toStringz gives me a immutable(char)*, which 
sounds like the same thing but isn't. and .dup on that just 
explodes. cast doesn't seem to work.  to! doesn't seem to work.

I know there "is" a solution, it's just so odd to have this much 
difficulty using a string.


More information about the Digitalmars-d-learn mailing list