//名字为a.d
import std.stdio;
void main() {
double number;
readf(" %s", &number);
writeln(number * 2);
}//太奇怪,这么一个程序`300kb`?,看来d这确实`标准库和运行时`太大了.
Command a >1.txt
, pay attention to enter 数字
. Enter other words, will always enter down.
Similarly, 2.txt
enter the number, then the command a <2.txt
, the console shows the results came.
Can be used simultaneously a <2.txt >1.txt
. Can be used |
to connect them together.
This will be 上一个程序
the output (conduit to) => 下一个程序
is input.
file
was bom 字节序标记
, bulk, small head, UTF8. 3 bytes for a specific utf16,32
labeled bulk head.
with std.file
the File
structure
when reading can be multithreaded / multi-program simultaneous read and write time is necessary to 锁
the.
File file = File("student_records", "r");
There are r,w,a,w+,a+
other ways.
localized open the file area, closed automatically out of the area, other 栈对象/局部对象
the same
as a different file is then opened
file.close();//先关闭
file.open("student_records","r");//再打开
//从文件读写
writeln("hello");
stdout.writeln("hello");//与上一样
file.writeln("hello");//写至特定文件
eof
End of the file list, the file in this module , exists
determines whether there is a file
the file open mode:
r
, reading from the beginning.
r+
: Read-write (re-write),
w
the file does not exist, an empty build file exists, i.e., is always empty.. 空文件
.
w+
, and uplink the same, but there are 读
privileges.
a
additional, the file does not exist, build an empty file exists, preserve the contents, and ready to write the end of the file content
a+
, and write on, like, read it from the beginning to read. reading can also writable.
can add b
, expressed as a 二进制
reading, but in the posix
system, useless,
import std.stdio;
void main() {
File file = File("student_records", "w");//模式
file.writeln("Name : ", "Zafer");
file.writeln("Number: ", 123);
file.writeln("Class : ", "1A");
}//readf,就像读流一样
Write to a file, and use stdout
the same.
Because File needs a constant 串
, if it is char[]
, you need idup
to convert it, then.
import std.stdio;
import std.string;
void main() {
File file = File("student_records", "r");
//读文件,这种方式,其实不是很方便.
while (!file.eof()) {
string line = strip(file.readln());
writeln("read line -> |", line);
}
}
This auto var = VeryLongTypeName( / * ... * /);
fact is still a bit uncomfortable .c ++ so.
型 a{...};
On the beginning of the end. Is not Gengshuang?
auto duration = 42;
auto distance = 1.2;
auto greeting = "Hello";
auto vehicle = BeautifulBicycle("blue");
These auto
, in fact 占位符
, derives its optimum type.
typeof
Similar c ++ is decltype(...)
derived types.
In 模板与插件
very useful in.