getting started with std.csv

yazd via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Mon Apr 6 22:49:47 PDT 2015


I got this to work with:

```
import std.stdio, std.file, std.csv, std.range;

void main()
{
	std.file.write("test.csv", "0,1,abc\n2,3,def");
	scope(exit) std.file.remove("test.csv");

	static struct Rec { int a, b; char[] c; }

	auto file = File("test.csv", "r");
	foreach (s; csvReader!Rec(file.byLine().joiner("\n")))
	{
		writeln("struct -> ", s);
	}
}
```

I am not sure about using `file.byLine()` here, because `byLine` 
reuses its buffer, but this is working correctly (for some 
reason, anyone can comment?) as far as I tested.


More information about the Digitalmars-d-learn mailing list