How can I concatenate a string, a char array and an int

Anders S via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Tue Nov 29 02:21:24 PST 2016


Hi guys,

just started to get into Dlang, comming from C and C++ I like to 
use methods like there if possible.

Now I want to catenate something like this, but don't get it to 
work
in standard C i code:
    char str[80];
    sprintf(str, "This is a number = %f", 3.14356);

Now in Dlang and import core.stdc.string and
code:
     char [80] str;
     sprintf(str, "This is a number = %d", 314356);
     writefln("%s", str);

but get error
Error: function core.stdc.stdio.sprintf (char* s, const(char*) 
format, ...) is not callable using argument types (char[80], 
string, int)

Nor does this work
    char [50] temp = "This is a number";
    string greeting5= temp~" "~314356;
    writefln("%s",greeting5);

result in error:
Error: incompatible types for ((cast(const(char)[])temp ~ " ") ~ 
(314356)): 'char[]' and 'int'


Any ideas or hints?
/anders





More information about the Digitalmars-d-learn mailing list