best replacement for - cout << "hello D" << endl; ?
Frits van Bommel
fvbommel at REMwOVExCAPSs.nl
Thu Jul 12 01:06:08 PDT 2007
Bruce Adams wrote:
> Jarrett Billingsley Wrote:
>
[snip]
>> void myWritefln(T...)(T args)
>> {
>> foreach(arg; args)
>> writef("%s", arg);
>>
>> writefln();
>> }
>>
>> myWritefln("Hi! ", 5, " that's all.");
>>
[snip]
>>
> I believe this is exactly what I'm looking for.
> I see this is actually in the example for variadic templates.
> http://www.digitalmars.com/d/variadic-function-templates.html
>
> Just one small problem. I can't get it to compile. At first I thought
> you were using incomplete/pseudo code to demonstrate but now I'm guessing maybe the compiler I'm using is incomplete.
>
> void myWritefln(T...)(T args) // line 7
> {
> foreach(arg; args) // line 9
> writef("%s", arg);
>
> writefln();
> }
>
> test.d:7: found '...' when expecting ')'
> test.d:7: semicolon expected following function declaration
> test.d:7: Declaration expected, not ')'
> test.d:9: no identifier for declarator args
> test.d:9: semicolon expected, not ')'
> test.d:9: Declaration expected, not ')'
> test.d:12: no identifier for declarator writefln
> test.d:13: unrecognized declaration
>
> F:\projects>gdc --version
> gdc (GCC) 3.4.4 (cygming special, gdc 0.23, using dmd 1.007))
It was /slightly/ incomplete, but I can't reproduce your error messages.
This works for me, using "gdc (GCC) 4.1.1 20060524 ( (gdc 0.23, using
dmd 1.007))" (Linux x64 version):
---
import std.stdio;
void myWritefln(T...)(T args)
{
foreach(arg; args)
writef("%s", arg);
writefln();
}
void main() {
myWritefln("Hi! ", 5, " that's all.");
}
---
More information about the Digitalmars-d-learn
mailing list