Error "Unexpected '\n' when converting from type LockingTextReader to type int"

rikki cattermole rikki at cattermole.co.nz
Wed Sep 7 23:31:29 UTC 2022


On 08/09/2022 11:24 AM, Synopsis wrote:
> On Wednesday, 7 September 2022 at 23:06:44 UTC, rikki cattermole wrote:
>> Text in buffer: "123\n"
>>
>> Read: "123"
>> Text in buffer: "\n"
>>
>> Read: exception, expecting number for "\n"
>>
>> Changing your readf format specifier to include the new line should work.
>>
>> https://dlang.org/phobos/std_stdio.html#.File.readf
> 
> 
> Thank you!
> Adding the \n seems to solve my problem: ```readf("%s\n", &f1.num)```
> 
> I have two further questions about this!
> 
> a- What is the difference with this syntax with the exclamation mark? 
> ```readf!"%s\n"(f1.num);```

That is a template.

It'll type check that the format specifier matches your arguments.

https://tour.dlang.org/tour/en/basics/templates

> b- Do I need to put ```/n``` in every readf statement? I mean, 
> considering that every input gets entered after pressing intro key (and 
> I guess this is what introduce the \n)

Yes.



More information about the Digitalmars-d-learn mailing list