Advertisement
WeltEnSTurm

D vs C++ (simple)

Sep 23rd, 2011
367
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.81 KB | None | 0 0
  1.  
  2. // D
  3.  
  4. import std.stdio;
  5. import std.file;
  6.  
  7. void main(string[] args){
  8.     char[] bytes;
  9.     try
  10.         bytes = cast(char[]) std.file.read("input.txt");
  11.     catch(Exception e){
  12.         writeln("Failed to open file.");
  13.         return;
  14.     }
  15.     try
  16.         std.file.append("output.txt", cast(void[]) (bytes ~ '\n'));
  17.     catch(Exception e){
  18.         writeln("Failed to write to file.");
  19.         return;
  20.     }
  21. }
  22.  
  23. // C++
  24.  
  25. #include <fstream>
  26. #include <iostream>
  27.  
  28. int main(int argc, char* argv[]){
  29.     std::ifstream infile("Whatever.txt");
  30.     std::ofstream oufile("Whatever2.txt", std::ios::app);
  31.     if(infile.is_open() && oufile.is_open()){
  32.         char buf[512];
  33.         while(infile.good()){
  34.             infile.getline(buf, 512);
  35.             oufile << buf << '\n';
  36.         }
  37.     }else{
  38.         std::cout << "Failed to open files." << std::endl;
  39.     }
  40.     infile.close();
  41.     oufile.close();
  42.     return 0;
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement