WeixiangYan/CodeTransOcean huggingface dataset:
Task: Find words which contains more than 3 e vowels


C++: #include <iostream>
#include <fstream>

bool test(const std::string &line) {
    unsigned int e = 0;
    for (char c : line) {
        switch(std::tolower(c)) {
            case 'a': return false;
            case 'i': return false;
            case 'o': return false;
            case 'u': return false;
            case 'e': ++e;
        }
    }
    return e > 3;
}

int main() {
    std::ifstream dict{"unixdict.txt"};
    
    if (! dict.is_open()) {
        std::cerr << "Cannot open unixdict.txt\n";
        return 3;
    }
    
    for (std::string line; std::getline(dict, line);) {
        if (test(line)) std::cout << line << std::endl;
    }
    
    return 0;
}










Ada: with Ada.Text_Io;
with Ada.Strings.Maps;
with Ada.Strings.Fixed;

procedure Find_Three_E is
   use Ada.Text_Io;
   use Ada.Strings;
   use type Ada.Strings.Maps.Character_Set;

   Filename   : constant String  := "unixdict.txt";
   Y_Is_Vowel : constant Boolean := False;
   Set_E      : constant Maps.Character_Set := Maps.To_Set ("eE");
   Set_Y      : constant Maps.Character_Set := Maps.To_Set ("yY");
   Set_Others : constant Maps.Character_Set :=
     Maps.To_Set ("aiouAIOU") or (if Y_Is_Vowel then Set_Y else Maps.Null_Set);
   File       : File_Type;
begin
   Open (File, In_File, Filename);
   while not End_Of_File (File) loop
      declare
         Word         : constant String  := Get_Line (File);
         Count_E      : constant Natural := Fixed.Count (Word, Set_E);
         Count_Others : constant Natural := Fixed.Count (Word, Set_Others);
      begin
         if Count_E > 3 and Count_Others = 0 then
            Put_Line (Word);
         end if;
      end;
   end loop;
   Close (File);
end Find_Three_E;
Task: Mosaic matrix


C++: #include <concepts>
#include <iostream>



void PrintMatrix(std::predicate<int, int, int> auto f, int size)
{
  for(int y = 0; y < size; y++)
  {
    for(int x = 0; x < size; x++)
    {
      std::cout << " " << f(x, y, size);
    }
    std::cout << "\n";
  }
  std::cout << "\n";
}

int main()
{
  
  auto mosaic = [](int x, int y, [[maybe_unused]]int size)
  {
    return (x + y) % 2 == 0;
  };

  PrintMatrix(mosaic, 8);
  PrintMatrix(mosaic, 9);
}










Ada: with Ada.Text_Io; use Ada.Text_Io;
with Ada.Command_Line;

procedure Mosaic_Matrix is

   type Matrix_Type is array (Positive range <>, Positive range <>) of Character;

   function Mosaic (Length : Natural) return Matrix_Type is
   begin
      return M : Matrix_Type (1 .. Length, 1 .. Length) do
         for Row in M'Range (1) loop
            for Col in M'Range (2) loop
               M (Row, Col) := (if (Row + Col) mod 2 = 0
                                then '1' else '.');
            end loop;
         end loop;
      end return;
   end Mosaic;

   procedure Put (M : Matrix_Type) is
   begin
      for Row in M'Range (1) loop
         for Col in M'Range (2) loop
            Put (' ');
            Put (M (Row, Col));
         end loop;
         New_Line;
      end loop;
   end Put;

begin
   Put (Mosaic (Length => Natural'Value (Ada.Command_Line.Argument (1))));

exception
   when others =>
      Put_Line ("Usage: ./mosaic_matrix <side-length>");

end Mosaic_Matrix;
Task: Numbers in base-16 representation that cannot be written with decimal digits


C++: #include<iostream>
using namespace std;

int main()
{
 int q,r;

 for(q=0;q<16;q++){
   for(r=10;r<16;r++){
     std::cout<<16*q+r<<" ";
   }
 }

return 0;
}










Ada: with Ada.Text_IO;

procedure Numbers_In_Base_16 is

   package Natural_IO is new Ada.Text_IO.Integer_IO (Natural);
   use Ada.Text_IO, Natural_IO;

   function Is_Hex_Only (Value : Natural) return Boolean
   is (Value = 0 or
         (Value mod 16 >= 10 and then Is_Hex_Only (Value / 16)));

   subtype Test_Range is Natural range 1 .. 499;
   Count : Natural := 0;
begin
   for A in Test_Range loop
      if Is_Hex_Only (A) then
         Count := Count + 1;
         Put (A, Width => 3); Put (" = ");
         Put (A, Width => 6, Base => 16); Put ("   ");
         if Count mod 5 = 0 then
            New_Line;
         end if;
      end if;
   end loop;
   New_Line;
   Default_Width := 0;
   Put ("There are "); Put (Count);
   Put (" numbers in range ");
   Put (Test_Range'First); Put (" .. ");
   Put (Test_Range'Last);
   Put (" without decimal digits in hex representation.");
   New_Line;
end Numbers_In_Base_16;
Task: Find words with alternating vowels and consonants


C++: #include <cstdlib>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <string>

bool is_vowel(char ch) {
    switch (ch) {
    case 'a': case 'A':
    case 'e': case 'E':
    case 'i': case 'I':
    case 'o': case 'O':
    case 'u': case 'U':
        return true;
    }
    return false;
}

bool alternating_vowels_and_consonants(const std::string& str) {
    for (size_t i = 1, len = str.size(); i < len; ++i) {
        if (is_vowel(str[i]) == is_vowel(str[i - 1]))
            return false;
    }
    return true;
}

int main(int argc, char** argv) {
    const char* filename = argc < 2 ? "unixdict.txt" : argv[1];
    std::ifstream in(filename);
    if (!in) {
        std::cerr << "Cannot open file '" << filename << "'.\n";
        return EXIT_FAILURE;
    }
    std::string line;
    for (int n = 1; getline(in, line); ) {
        if (line.size() > 9 && alternating_vowels_and_consonants(line))
            std::cout << std::setw(2) << n++ << ": " << line << '\n';
    }
    return EXIT_SUCCESS;
}










Ada: with Ada.Text_Io;
with Ada.Strings.Fixed;

procedure Find_Alternating is
   use Ada.Text_Io;

   function Is_Vowel (Letter : Character) return Boolean
   is (Ada.Strings.Fixed.Index ("aeiou", "" & Letter) /= 0);

   Filename : constant String := "unixdict.txt";
   File     : File_Type;
begin
   Open (File, In_File, Filename);
   while not End_Of_File (File) loop
      declare
         Word   : constant String  := Get_Line (File);
         Failed : Boolean := False;
         Vowel  : Boolean := not Is_Vowel (Word (Word'First));
      begin
         for Letter of Word loop
            if Vowel = Is_Vowel (letter) then
               Failed := True;
               exit;
            end if;
            Vowel := not Vowel;
         end loop;
         if not Failed and Word'Length > 9 then
            Put_Line (Word);
         end if;
      end;
   end loop;
   Close (File);
end Find_Alternating;
Task: Input_Output for lines of text


C++: #include <iostream>
#include <vector>

int main()
{
    
    int numberOfLines;
    std::cin >> numberOfLines;
    std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n'); 
    
    
    std::vector<std::string> lines(numberOfLines);    
    for(int i = 0; i < numberOfLines; ++i)
    {
        std::getline(std::cin, lines[i]);
    }

    
    for(const auto& value : lines)
    {
        std::cout << value << "\n";
    }
}










Ada: 







with Ada.Text_IO; use Ada.Text_IO;
with Ada.Integer_Text_IO; use Ada.Integer_Text_IO;

procedure Main is
   Num_Lines : Integer;
begin
   Get(Num_Lines);
   Skip_Line;
   for I in 1..Num_Lines loop
      Put_Line(Get_Line);
   end loop;
end Main;
Task: Length of an arc between two angles


C++: #include <iostream>

#define _USE_MATH_DEFINES
#include <math.h>

double arcLength(double radius, double angle1, double angle2) {
    return (360.0 - abs(angle2 - angle1)) * M_PI * radius / 180.0;
}

int main() {
    auto al = arcLength(10.0, 10.0, 120.0);
    std::cout << "arc length: " << al << '\n';
    return 0;
}










Ada: with Ada.Text_Io;
with Ada.Numerics;

procedure Calculate_Arc_Length is
   use Ada.Text_Io;

   type Angle_Type is new Float range 0.0 .. 360.0;       
   type Distance   is new Float range 0.0 .. Float'Last;  

   function Major_Arc_Length (Angle_1, Angle_2 : Angle_Type;
                              Radius           : Distance)
                             return Distance
   is
      Pi            : constant := Ada.Numerics.Pi;
      Circumference : constant Distance   := 2.0 * Pi * Radius;
      Major_Angle   : constant Angle_Type := 360.0 - abs (Angle_2 - Angle_1);
      Arc_Length    : constant Distance   :=
        Distance (Major_Angle) / 360.0 * Circumference;
   begin
      return Arc_Length;
   end Major_Arc_Length;

   package Distance_Io is new Ada.Text_Io.Float_Io (Distance);

   Arc_Length : constant Distance := Major_Arc_Length (Angle_1 =>  10.0,
                                                       Angle_2 => 120.0,
                                                       Radius  =>  10.0);
begin
   Put ("Arc length : ");
   Distance_Io.Put (Arc_Length, Exp => 0, Aft => 4);
   New_Line;
end Calculate_Arc_Length;
Task: Shift list elements to left by 3


C++: #include <algorithm>
#include <iostream>
#include <iterator>
#include <vector>

template <typename T>
void print(const std::vector<T>& v) {
    std::copy(v.begin(), v.end(), std::ostream_iterator<T>(std::cout, " "));
    std::cout << '\n';
}

int main() {
    std::vector<int> vec{1, 2, 3, 4, 5, 6, 7, 8, 9};
    std::cout << "Before: ";
    print(vec);
    std::rotate(vec.begin(), vec.begin() + 3, vec.end());
    std::cout << " After: ";
    print(vec);
}










Ada: with Ada.Text_Io;

procedure Shift_Left is

   Shift_Count : constant := 3;

   type List_Type is array (Positive range <>) of Integer;

   procedure Put_List (List : List_Type) is
      use Ada.Text_Io;
   begin
      for V of List loop
         Put (V'Image); Put ("  ");
      end loop;
      New_Line;
   end Put_List;

   Shift : List_Type := (1, 2, 3, 4, 5, 6, 7, 8, 9);
begin
   Put_List (Shift);

   Shift :=
     Shift (Shift'First + Shift_Count .. Shift'Last) &
       Shift (Shift'First .. Shift_Count);

   Put_List (Shift);
end Shift_Left;
Task: Numbers with same digit set in base 10 and base 16


C++: #include <iostream>
#include <iomanip>
#include <bitset>

const int LIMIT = 100000;

std::bitset<16> digitset(int num, int base) {
    std::bitset<16> set;
    for (; num; num /= base) set.set(num % base);
    return set;
}

int main() {
    int c = 0;
    for (int i=0; i<LIMIT; i++) {
        if (digitset(i,10) == digitset(i,16)) {
            std::cout << std::setw(7) << i;
            if (++c % 10 == 0) std::cout << std::endl;
        }
    }
    std::cout << std::endl;
    return 0;
}










Ada: with Ada.Text_Io;

procedure Same_Digits is

   Columns : constant := 10;
   Width   : constant := 8;

   type Set_Type is array (0 .. 15) of Boolean;

   function Digit_Set_Of (N : Natural; Base : Natural) return Set_Type is
      Nn  : Natural  := N;
      Set : Set_Type := (others => False);
   begin
      while Nn /= 0 loop
         Set (Nn mod Base) := True;
         Nn := Nn / Base;
      end loop;
      return Set;
   end Digit_Set_Of;

   package Natural_Io is new Ada.Text_Io.Integer_Io (Natural);
   use Ada.Text_Io, Natural_Io;

   Count : Natural := 0;
begin
   for N in 0 .. 99_999 loop
      if Digit_Set_Of (N, Base => 10) = Digit_Set_Of (N, Base => 16) then
         Count := Count + 1;
         Put (N, Width => Width);
         if Count mod Columns = 0 then
            New_Line;
         end if;
      end if;
   end loop;
   New_Line;
   Put ("Total numbers: "); Put (Count, Width => 3); New_Line;
end Same_Digits;
Task: Matrix with two diagonals


C++: #include <concepts>
#include <iostream>



void PrintMatrix(std::predicate<int, int, int> auto f, int size)
{
  for(int y = 0; y < size; y++)
  {
    for(int x = 0; x < size; x++)
    {
      std::cout << " " << f(x, y, size);
    }
    std::cout << "\n";
  }
  std::cout << "\n";
}

int main()
{
  
  auto diagonals = [](int x, int y, int size)
  {
    return x == y || ((size - x - 1) == y);
  };
  
  PrintMatrix(diagonals, 8);
  PrintMatrix(diagonals, 9);
}










Ada: with Ada.Text_Io; use Ada.Text_Io;
with Ada.Command_Line;

procedure Matrix_With_Diagonals is

   type Matrix_Type is array (Positive range <>, Positive range <>) of Character;

   function Matrix_X (Length : Natural) return Matrix_Type is
   begin
      return M : Matrix_Type (1 .. Length, 1 .. Length) do
         for Row in M'Range (1) loop
            for Col in M'Range (2) loop
               M (Row, Col) := (if
                                  Row = Col or else
                                  Row = M'Last (2) - (Col - M'First (1))
                                then '1' else '0');
            end loop;
         end loop;
      end return;
   end Matrix_X;

   procedure Put (M : Matrix_Type) is
   begin
      for Row in M'Range (1) loop
         for Col in M'Range (2) loop
            Put (' ');
            Put (M (Row, Col));
         end loop;
         New_Line;
      end loop;
   end Put;

begin
   Put (Matrix_X (Length => Natural'Value (Ada.Command_Line.Argument (1))));

exception
   when others =>
      Put_Line ("Usage: ./matrix_with_diagonals <side-length>");

end Matrix_With_Diagonals;
Task: Words containing _the_ substring


C++: #include <iostream>
#include <fstream>

int main() {
    std::string word;
    std::ifstream file("unixdict.txt");
 
    if (!file) {
        std::cerr << "Cannot open unixdict.txt" << std::endl;
        return -1;
    }
    while (file >> word) {
        if (word.length() > 11 && word.find("the") != std::string::npos)
            std::cout << word << std::endl;
    }
    return 0;
}










Ada: with Ada.Text_IO;            use Ada.Text_IO;
with Ada.Strings.Fixed;      use Ada.Strings.Fixed;
with Ada.Characters.Latin_1; use Ada.Characters.Latin_1;

procedure Main is
   type col_count is mod 6;
   package AF renames Ada.Strings.Fixed;

   file_name : String             := "unixdict.txt";
   The_File  : File_Type;
   Inpt_Str  : String (1 .. 40);
   Length    : Natural;
   pattern   : String             := "the";
   Columns   : col_count          := 0;
   Tally     : Natural            := 0;
   sep       : constant Character := HT;
begin

   Open (File => The_File, Mode => In_File, Name => file_name);

   while not End_Of_File (The_File) loop
      Get_Line (File => The_File, Item => Inpt_Str, Last => Length);

      if Length > 11
        and then
          AF.Count (Source => Inpt_Str (1 .. Length), Pattern => pattern) > 0
      then
         Tally   := Tally + 1;
         Columns := Columns + 1;
         Put (Inpt_Str (1 .. Length) & sep);
         if Columns = 0 then
            New_Line;
         end if;
      end if;
   end loop;
   New_Line;
   Put_Line ("Found" & Tally'Image & " ""the"" words");
   Close (The_File);
end Main;
Task: Four sides of square


C++: #include <concepts>
#include <iostream>



void PrintMatrix(std::predicate<int, int, int> auto f, int size)
{
  for(int y = 0; y < size; y++)
  {
    for(int x = 0; x < size; x++)
    {
      std::cout << " " << f(x, y, size);
    }
    std::cout << "\n";
  }
  std::cout << "\n";
}

int main()
{
  
  auto fourSides = [](int x, int y, int size)
  {
    return x == 0 || (y == 0) || (x == size - 1) || (y == size - 1);
  };

  PrintMatrix(fourSides, 8);
  PrintMatrix(fourSides, 9);
}










Ada: with Ada.Text_Io;
with Ada.Command_Line;

procedure Four_Sides is

   type Matrix_Type is array (Natural range <>, Natural range <>) of Character;

   function Hollow (Length : Natural) return Matrix_Type is
   begin
      return M : Matrix_Type (1 .. Length, 1 .. Length) do
         for Row in M'Range(1) loop
            for Col in M'Range (2) loop
               M (Row, Col) := (if Row in M'First (1) | M'Last (1) or
                                  Col in M'First (2) | M'Last (2)
                                then '1' else '0');
            end loop;
         end loop;
      end return;
   end Hollow;

   procedure Put (M : Matrix_Type) is
   begin
      for Row in M'Range (1) loop
         for Col in M'Range (2) loop
            Ada.Text_Io.Put (" ");
            Ada.Text_Io.Put (M(Row,Col));
         end loop;
         Ada.Text_Io.New_Line;
      end loop;
   end Put;

begin
   Put (Hollow (Length => Natural'Value (Ada.Command_Line.Argument (1))));
exception
   when others =>
      Ada.Text_Io.Put_Line ("Usage: ./four_sides <length>");
end Four_Sides;
Task: Numeric separator syntax


C++: 

#include <iostream>
using namespace std;

int main()
{
    long long int a = 30'00'000;

    std::cout <<"And with the ' in C++ 14 : "<< a << endl;

    return 0;
}










Ada: with Ada.Text_IO;       use Ada.Text_IO;
with Ada.Float_Text_IO; use Ada.Float_Text_IO;

procedure Main is
   type u64 is mod 2**64;
   pi       : constant Float := 
     3.14159_26535_89793_23846_26433_83279_50288_41971_69399_37511;
   Trillion : u64            := 1_000_000_000_000;
begin
   Put ("pi : ");
   Put (Item => pi, Exp => 0, Aft => 7);
   New_Line;
   Put_Line ("Trillion : " & Trillion'Image);
end Main;
Task: Distinct power numbers


C++: #include <iostream>
#include <set>
#include <cmath>

int main() {
    std::set<int> values;
    for (int a=2; a<=5; a++)
        for (int b=2; b<=5; b++)
            values.insert(std::pow(a, b));
    
    for (int i : values)
        std::cout << i << " ";
    
    std::cout << std::endl;
    return 0;
}










Ada: with Ada.Text_Io;
with Ada.Containers.Doubly_Linked_Lists;

procedure Power_Numbers is

   package Number_Lists   is new Ada.Containers.Doubly_Linked_Lists (Integer);
   package Number_Sorting is new Number_Lists.Generic_Sorting;
   use Number_Lists, Ada.Text_Io;

   List : Number_Lists.List;
begin
   for A in 2 .. 5 loop
      for B in 2 .. 5 loop
         declare
            R : constant Integer := A**B;
         begin
            if not List.Contains (R) then
               List.Append (R);
            end if;
         end;
      end loop;
   end loop;

   Number_Sorting.Sort (List);

   for E of List loop
      Put (Integer'Image (E));
      Put (" ");
   end loop;
   New_Line;

end Power_Numbers;
Task: Unique characters


C++: #include <iostream>
#include <map>

int main() {
    const char* strings[] = {"133252abcdeeffd", "a6789798st", "yxcdfgxcyz"};
    std::map<char, int> count;
    for (const char* str : strings) {
        for (; *str; ++str)
            ++count[*str];
    }
    for (const auto& p : count) {
        if (p.second == 1)
            std::cout << p.first;
    }
    std::cout << '\n';
}










Ada: with Ada.Text_Io;

procedure Unique_Characters is

   List : array (Character) of Natural := (others => 0);

   procedure Count (Item : String) is
   begin
      for C of Item loop
         List (C) := List (C) + 1;
      end loop;
   end Count;

   procedure Put_Only_Once is
      use Ada.Text_Io;
   begin
      for C in List'Range loop
         if List (C) = 1 then
            Put (C);
            Put (' ');
         end if;
      end loop;
      New_Line;
   end Put_Only_Once;

begin
   Count ("133252abcdeeffd");
   Count ("a6789798st");
   Count ("yxcdfgxcyz");
   Put_Only_Once;
end Unique_Characters;
Task: Hello world_Newbie


C++: #include <iostream>
int main() {
    using namespace std;
    cout << "Hello, World!" << endl;
    return 0;
}










Ada: procedure Main is

begin
   
   null;
end Main;
Task: Here document


C++: #include <iostream> 

int main()
{
  std::cout <<
R"EOF(  A  raw  string  begins  with  R,  then a double-quote ("),  then an optional
identifier (here I've used "EOF"),  then an opening parenthesis ('(').  If you
use  an  identifier,  it  cannot  be longer than 16 characters,  and it cannot
contain a space,  either opening or closing parentheses, a backslash, a tab, a
vertical tab, a form feed, or a newline.

  It  ends with a closing parenthesis (')'),  the identifer (if you used one),
and a double-quote.

  All  characters are okay in a raw string,  no escape sequences are necessary
or recognized, and all whitespace is preserved.
)EOF";
}










Ada: with Ada.Containers.Indefinite_Vectors, Ada.Text_IO;

procedure Here_Doc is

   package String_Vec is new Ada.Containers.Indefinite_Vectors
     (Index_Type   => Positive,
      Element_Type => String);

   use type String_Vec.Vector;

   Document: String_Vec.Vector := String_Vec.Empty_Vector
    & "This is a vector of strings with the following properties:"
    & "  - indention is preserved, and"
    & "  - a quotation mark '""' must be ""escaped"" by a double-quote '""""'.";
begin
   Document := Document & "Have fun!";
   for I in Document.First_Index .. Document.Last_Index loop
      Ada.Text_IO.Put_Line(Document.Element(I));
   end loop;
end Here_Doc;
Task: Special characters


C++: std::cout << "Tür\n";
std::cout << "T\u00FC\n";










Ada: with Ada.Text_IO;  use Ada.Text_IO;

procedure Test is
begin
   Put ("Quote """ & ''' & """" & Character'Val (10));
end Test;
Task: Base 16 numbers needing a to f


C++: #include <iomanip>
#include <iostream>



bool nondecimal(unsigned int n) {
    for (; n > 0; n >>= 4) {
        if ((n & 0xF) > 9)
            return true;
    }
    return false;
}

int main() {
    unsigned int count = 0;
    for (unsigned int n = 0; n < 501; ++n) {
        if (nondecimal(n)) {
            ++count;
            std::cout << std::setw(3) << n << (count % 15 == 0 ? '\n' : ' ');
        }
    }
    std::cout << "\n\n" << count << " such numbers found.\n";
}










Ada: with Ada.Text_Io;

procedure Base_16_Numbers is
   Columns : constant := 24;
   Base    : constant := 16;

   function Has_A_To_F (N : Positive) return Boolean is
      C : Natural := N;
   begin
      while C > 0 loop
         if C mod Base in 16#A# .. 16#F# then
            return True;
         end if;
         C := C / Base;
      end loop;
      return False;
   end Has_A_To_F;

   package Natural_Io is new Ada.Text_Io.Integer_Io (Natural);
   use Ada.Text_Io;
   Count : Natural := 0;
begin
   for N in 1 .. 500 loop
      if Has_A_To_F (N) then
         Count := Count + 1;
         Natural_Io.Put (N, Width => 5);
         if Count mod Columns = 0 then
            New_Line;
         end if;
      end if;
   end loop;
   New_Line (2);
   Put ("Total count: "); Natural_Io.Put (Count, Width => 3); New_Line;
end Base_16_Numbers;
Task: Address of a variable


C++: int i;
void* address_of_i = &i;










Ada: The_Address : System.Address;
I : Integer;
The_Address := I'Address;
Task: Fixed length records


C++: #include <algorithm>
#include <cstdlib>
#include <fstream>
#include <iostream>

void reverse(std::istream& in, std::ostream& out) {
    constexpr size_t record_length = 80;
    char record[record_length];
    while (in.read(record, record_length)) {
        std::reverse(std::begin(record), std::end(record));
        out.write(record, record_length);
    }
    out.flush();
}

int main(int argc, char** argv) {
    std::ifstream in("infile.dat", std::ios_base::binary);
    if (!in) {
        std::cerr << "Cannot open input file\n";
        return EXIT_FAILURE;
    }
    std::ofstream out("outfile.dat", std::ios_base::binary);
    if (!out) {
        std::cerr << "Cannot open output file\n";
        return EXIT_FAILURE;
    }
    try {
        in.exceptions(std::ios_base::badbit);
        out.exceptions(std::ios_base::badbit);
        reverse(in, out);
    } catch (const std::exception& ex) {
        std::cerr << "I/O error: " << ex.what() << '\n';
        return EXIT_FAILURE;
    }
    return EXIT_SUCCESS;
}










Ada: with Ada.Text_IO; use Ada.Text_IO;

procedure Main is
   subtype Block is String (1 .. 80);
   Infile_Name  : String := "infile.dat";
   outfile_Name : String := "outfile.dat";
   Infile       : File_Type;
   outfile      : File_Type;

   Line : Block := (Others => ' ');
begin
   Open (File => Infile, Mode => In_File, Name => Infile_Name);
   Create (File => outfile, Mode => Out_File, Name => outfile_Name);

   Put_Line("Input data:");
   New_Line;
   while not End_Of_File (Infile) loop
      Get (File => Infile, Item => Line);
      Put(Line);
      New_Line;
      for I in reverse Line'Range loop
         Put (File => outfile, Item => Line (I));
      end loop;
   end loop;
   
   Close (Infile);
   Close (outfile);

   Open(File => infile,
        Mode => In_File,
        Name => outfile_name);
   New_Line;
   Put_Line("Output data:");
   New_Line;
   while not End_Of_File(Infile) loop
      Get(File => Infile,
          Item => Line);
      Put(Line);
      New_Line;
   end loop;
end Main;