strange file behaviour
Ali Çehreli
acehreli at yahoo.com
Sun Mar 4 11:57:03 PST 2012
On 03/04/2012 11:43 AM, maarten van damme wrote:
> hello,
> I wrote this little test:
> import std.stdio;
>
> void main(){
> auto testfile=new File("test.txt");
That is a pointer but lines() takes a File. Either construct testfile
like this:
auto testfile = File("test.txt");
or use lines(*testfile) in the foreach loop.
> foreach(string line;lines(testfile))
> writeln(line);
> }
> and get as error
> src\main.d(6): Error: constructor std.stdio.lines.this (File f, dchar
> terminator = cast(dchar)'\x0a') is not callable using argument types
(File*)
> src\main.d(6): Error: cannot implicitly convert expression (testfile) of
> type File* to File
>
> Why?
> I've also noticed the argument to lines in the example was a stream
but now
> it claims to be a File. when I feed it a File it complains it is given a
> *File... what am I doing wrong?
>
Just a reminder that "If line has type char[], wchar[], dchar[], the
line's content will be reused (overwritten) across reads.":
http://dlang.org/phobos/std_stdio.html#lines
Ali
More information about the Digitalmars-d-learn
mailing list