Thanks for the extra info guys! D is one of my favorite languages
I'm currently learning. :)
On 7/5/22 8:14 PM, Gary Chike wrote:
On Monday, 20 June 2022 at 16:08:33 UTC, Ali Çehreli wrote:
On 6/20/22 07:00, Gary Chike wrote:
> Would it be appropriate to forego `readf`
> and read input as a string using `readln` ,benefiting from
the `strip`
> function, then convert to their
On 7/5/22 17:14, Gary Chike wrote:
> So, in order to use `parse!int()`, I would need to separate it into two
> statements with a variable acting as an intermediary:
> ```
> auto input = readln();
> auto age = parse!int(input);
Exactly. parse takes the input by reference (necessitating an
On Monday, 20 June 2022 at 16:08:33 UTC, Ali Çehreli wrote:
On 6/20/22 07:00, Gary Chike wrote:
> Would it be appropriate to forego `readf`
> and read input as a string using `readln` ,benefiting from
the `strip`
> function, then convert to their appropriate datatype
Makes sense. The following
On Monday, 20 June 2022 at 16:08:33 UTC, Ali Çehreli wrote:
Makes sense. The following are related as well:
https://dlang.org/library/std/conv/parse.html
https://dlang.org/library/std/format/read/formatted_read.html
Ali
Thank you so much for your input! Cheers! :)
On 6/20/22 07:00, Gary Chike wrote:
> Would it be appropriate to forego `readf`
> and read input as a string using `readln` ,benefiting from the `strip`
> function, then convert to their appropriate datatype
Makes sense. The following are related as well:
I should have qualified the above with: _ and I will be
performing operations on the numeric datatype, since just
outputting simply strings, as in the above example, would require
nothing more than string data types. :)
```d
module hello_world;
import std.stdio;
import std.string; // strip()
On Monday, 20 June 2022 at 00:43:17 UTC, Ali Çehreli wrote:
...
But when the program interacts with piped data, there may be
multiple \n characters and all of those might have to be
ignored before reading the next non-empty line. So you may want
to do readln.strip multiple times? I don't
On 6/19/22 15:52, Gary Chike wrote:
> On Saturday, 24 April 2021 at 22:13:45 UTC, Ali Çehreli wrote:
>> On 4/24/21 7:46 AM, PinDPlugga wrote:
>> ...
>> As a general solution, you can use a function like this:
>>
>> auto readLine(S = string)(File file = stdin) {
>> while (!file.eof) {
>>
On Saturday, 24 April 2021 at 22:13:45 UTC, Ali Çehreli wrote:
On 4/24/21 7:46 AM, PinDPlugga wrote:
...
As a general solution, you can use a function like this:
auto readLine(S = string)(File file = stdin) {
while (!file.eof) {
auto line = file.readln!S.strip;
if (!line.empty) {
On 4/24/21 7:46 AM, PinDPlugga wrote:
> write("Please enter a number: ");
> double number;
> readf(" %s", number);
Just to make sure, this is a common issue for other languages as well.
As the explanation, the character ('\n') that you injected into stdin by
pressing Enter is
On Saturday, 24 April 2021 at 14:46:06 UTC, PinDPlugga wrote:
I didn't want to necropost, but I ran into the same behaviour
as in this post:
https://forum.dlang.org/post/yfybveovbknvvxmio...@forum.dlang.org
and was just curious to understand it better.
[...]
I didn't want to necropost, but I ran into the same behaviour as
in this post:
https://forum.dlang.org/post/yfybveovbknvvxmio...@forum.dlang.org
and was just curious to understand it better.
If I call readln() after having previously called readf(), it
does not behave as expected:
```d
import
13 matches
Mail list logo