Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

template std.file.readText cannot deduce function from argument types !()(File)

Tags:

d

I am trying to use the readText function:

import std.stdio;
import std.file;

string xmlName = r"D:\files\123.xml";
File file;

void main()
{
    writeln("Edit source/app.d to start your project.");
    file = File(xmlName, "r");
    string file_text = file.readText;
}

I am getting an error:

Error: template std.file.readText cannot deduce function from argument types !()(File), candidates are:
C:\D\dmd2\windows\bin\..\..\src\phobos\std\file.d(499,3):        std.file.readText(S = string, R)(auto ref R name) if (isSomeString!S && (isInputRange!R && !isInfinite!R && isSomeChar!(ElementType!R) || is(StringTypeOf!R)))

What am I doing wrong?

like image 726
Dmitry Bubnenkov Avatar asked Oct 17 '22 06:10

Dmitry Bubnenkov


1 Answers

readText takes a string argument, being the file name to read from. Since you've opened the file with File(xmlName, "r"), you should be using the methods defined in std.stdio.File.

It seems what you want is to read the entirety of the file contents into a string. In this case, I suggest replacing the two last lines in your main function with string file_text = readText(xmlName);

like image 189
BioTronic Avatar answered Oct 21 '22 03:10

BioTronic