Advertisement
Guest User

Files by D

a guest
May 8th, 2014
199
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
D 1.34 KB | None | 0 0
  1. if (aCondition) {
  2.   // Предполагается, что объект файла был создан и используется здесь.
  3.   // ...
  4. } // ← Автоматически файл будет закрыт здесь при выходе из области видимости.
  5.   //   Нет необходимости закрывать его вручную.
  6.  
  7.  
  8.     file.close();
  9.     file.open("student_records", "r");
  10.  
  11.  
  12.     writeln("hello");         // запись в стандартный вывод
  13.     stdout.writeln("hello");  // тоже что и выше
  14.     file.writeln("hello");    // запись в файл
  15.  
  16.  
  17.     while (!file.eof()) {
  18.         /* ... */
  19.     }
  20.  
  21.  
  22. import std.file;
  23.  
  24. // ...
  25. if (exists(fileName)) {
  26.     // есть файл или каталог под этим именем
  27. }
  28. else {
  29.     // нет файла или каталога под этим именем
  30. }
  31.  
  32.  
  33. import std.stdio;
  34.  
  35. void main()
  36. {
  37.     File file = File("student_records", "w");
  38.  
  39.     file.writeln("Name  : ", "Zafer");
  40.     file.writeln("Number: ", 123);
  41.     file.writeln("Class : ", "1A");
  42. }
  43.  
  44.  
  45. import std.stdio;
  46. import std.string;
  47.  
  48. void main()
  49. {
  50.     File file = File("student_records", "r");
  51.  
  52.     while (!file.eof()) {
  53.         string line = chomp(file.readln());
  54.         writeln("read line -> |", line);
  55.     }
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement