Hello, comming from C++, I find it hard to remember and
understand how reading from file should be done in D. Especially
since I am not very good in functional programming. So I have a
file which looks like this:
1,2,3,4
5,6,7,8
9,11,11,12
and so on
How could I read it row by row and create
On 14/12/2016 4:42 AM, Namal wrote:
Hello, comming from C++, I find it hard to remember and understand how
reading from file should be done in D. Especially since I am not very
good in functional programming. So I have a file which looks like this:
1,2,3,4
5,6,7,8
9,11,11,12
and so on
How
On Tuesday, 13 December 2016 at 15:42:16 UTC, Namal wrote:
Hello, comming from C++, I find it hard to remember and
understand how reading from file should be done in D.
Especially since I am not very good in functional programming.
So I have a file which looks like this:
1,2,3,4
5,6,7,8
On Tuesday, 13 December 2016 at 16:57:40 UTC, Namal wrote:
Sorry if I wasn't clear. The array should be two demensional
and each line in text line should be a row in that 2x2 array.
Also, it should be saved as an integer.
Sorry if I wasn't clear. The array should be two demensional and
each line in text line should be a row in that 2x2 array.
On 12/13/2016 08:59 AM, Namal wrote:
On Tuesday, 13 December 2016 at 16:57:40 UTC, Namal wrote:
Sorry if I wasn't clear. The array should be two demensional and each
line in text line should be a row in that 2x2 array.
Also, it should be saved as an integer.
Here is another one:
import std.
On Tuesday, 13 December 2016 at 16:59:17 UTC, Namal wrote:
On Tuesday, 13 December 2016 at 16:57:40 UTC, Namal wrote:
Sorry if I wasn't clear. The array should be two demensional
and each line in text line should be a row in that 2x2 array.
Also, it should be saved as an integer.
And extendi
On Tuesday, 13 December 2016 at 21:13:26 UTC, Ali wrote:
And extending Ali's solution you can actually get the data in
to a two dimentional array at compile time and have it in
static memory with a small adjustment:
static immutable matrix = import("data.txt")
.split("\n")
.map!(a =>
On 12/15/2016 10:47 PM, KaattuPoochi wrote:
> On Tuesday, 13 December 2016 at 21:13:26 UTC, Ali wrote:
>>
>> And extending Ali's solution you can actually get the data in
>> to a two dimentional array at compile time and have it in static
>> memory with a small adjustment:
>>
>> static immutable m
On Friday, 16 December 2016 at 06:47:15 UTC, KaattuPoochi wrote:
On Tuesday, 13 December 2016 at 21:13:26 UTC, Ali wrote:
And extending Ali's solution you can actually get the data in
to a two dimentional array at compile time and have it in
static memory with a small adjustment:
static immu
On 12/15/2016 10:47 PM, KaattuPoochi wrote:
> On Tuesday, 13 December 2016 at 21:13:26 UTC, Ali wrote:
>>
>> And extending Ali's solution you can actually get the data in
>> to a two dimentional array at compile time and have it in static
>> memory with a small adjustment:
>>
>> static immutable m
On Friday, 16 December 2016 at 08:03:22 UTC, Ali Çehreli wrote:
shared static this() {
matrix =
(cast(immutable(int[width])*)buffer.ptr)[0..height];
// Make sure we did not copy into matrix
assert(cast(void*)matrix.ptr == cast(void*)buffer.ptr);
}
Thanks Ali, this is neat!!
I've having some trouble reading from a file.
I am trying to read a list of high scores, each on a separate line, like this:
440
0
0
0
0
But with my code, I get an error saying: Error: conversion.
Code:
//Load high scores
char[] file;
int[] highScoreList;
int nextScore;
file = cast(char[])read(
Michael P.:
> The output I get is:
> 440
> Error: conversion
>
> The high scores that are printed above is what is in the file.
> I am using DMD1.046 with Phobos.
Try:
import std.string: strip;
...
highScoreList ~= toInt(strip(file[0 .. nextScore]));
I have never understand the rationale of not
bearophile Wrote:
.
>
> Try:
> import std.string: strip;
> ...
> highScoreList ~= toInt(strip(file[0 .. nextScore]));
>
> I have never understand the rationale of not ignoring whitespace inside the
> toInt, I think it's an ugly design.
>
> Bye,
> bearophile
That didn't work for me. Doing this
>
> I have never understand the rationale of not ignoring whitespace inside
> the toInt, I think it's an ugly design.
>
Agreed!
16 matches
Mail list logo