On Sunday, 7 May 2017 at 13:57:47 UTC, JV wrote:
Hi guys
I'd like to know how to get an input from the user to be stored
in a .txt file using import std.file and is it possible to
directly write in a .txt file without using a variable to store
the user input?
Thanks for the answer in advance my mind is kinda jumbled about
this since im new to this language.
First of all see here:
https://dlang.org/phobos/std_stdio.html#.File
also:
import std.stdio; // for File
void main(){
// an output file with name file.txt
// w for writing
auto ofs = File( "file.txt", "w" );
// output file stream:
ofs.write( stdin.readln() ); // get a line from console
ofs.close();
}
cat file.txt:
This is the first line.
and for std.file:
https://dlang.org/phobos/std_file.html