Thanks for the replies, everyone.I guess I'll go with the double
conversion for now.
Hello everybody.
I have to convert a char* (from a C function) to long. At the
moment I'm using
long foo = to!long( to!string(bar) );
but this doesn't feel right... with 2 to calls. Is this the way
to go? Or is there something better?
Mars
24.01.2012 22:48, Mars пишет:
Hello everybody.
I have to convert a char* (from a C function) to long. At the moment
I'm using
long foo = to!long( to!string(bar) );
but this doesn't feel right... with 2 to calls. Is this the way to go?
Or is there something better?
Mars
This seems to work:
to go?
Or is there something better?
Mars
This seems to work:
char[] c = 123\0.dup;
auto l = parse!long(c);
writeln( l );
Yeah, but note that that's really equivalent to
auto foo = to!long(to!(char[])(bar));
except that you're creating an extra variable and using parse with its
Why not just go the good old way? you char* should be zero terminated
when coming from c.
private import core.stdc.stdlib,
std.stdio;
void main()
{
const(char)* str = 1234567890.ptr;
long lng = atoll(str);
writeln(lng);
}