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

2022-09-07 Thread Ali Çehreli via Digitalmars-d-learn

On 9/7/22 16:24, Synopsis wrote:

> a- What is the difference with this syntax with the exclamation mark?
> ```readf!"%s\n"(f1.num);```

That's the templated version, which is safer because it checks at 
compile time (important distinction) that the arguments and the format 
specifiers do match.


> b- Do I need to put ```/n``` in every readf statement?

Another option is to use a space character, which reads and skips any 
number of any whitespace character. I have written something about that 
here:


  http://ddili.org/ders/d.en/input.html

And this one talks about readln, which may be more suitable in some cases:

  http://ddili.org/ders/d.en/strings.html

And there is formattedRead:

  http://ddili.org/ders/d.en/strings.html#ix_strings.formattedRead

> Forgive me if I'm asking silly questions.

There is never a silly question. If a question came up, it is as 
legitimate as it gets.


And welcome to programming! :)

Ali



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

2022-09-07 Thread rikki cattermole via Digitalmars-d-learn

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", )```

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.



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

2022-09-07 Thread Synopsis via Digitalmars-d-learn
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", 
)```


I have two further questions about this!

a- What is the difference with this syntax with the exclamation 
mark? ```readf!"%s\n"(f1.num);```


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)



Forgive me if I'm asking silly questions.


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

2022-09-07 Thread rikki cattermole via Digitalmars-d-learn

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