File Input Output in Beef

Published on 18 January 2024 (Updated: 18 January 2024)

Welcome to the File Input Output in Beef page! Here, you'll find the source code for this program as well as a description of how the program works.

Current Solution

using System;
using System.IO;

namespace FileInputOutput;

class Program
{
    public static Result<void> WriteFile(StringView filename)
    {
        StreamWriter fs = scope .();
        Try!(fs.Create(filename));
        fs.WriteLine("Hello from Beef!");
        fs.WriteLine("This is line 1");
        fs.WriteLine("This is line 2");
        fs.WriteLine("Goodbye!");
        return .Ok;
    }

    public static Result<void> ReadFile(StringView filename)
    {
        StreamReader fs = scope .();
        Try!(fs.Open(filename));
        String line = scope .();
        while (fs.ReadLine(line) case .Ok)
        {
            Console.WriteLine(line);
            line.Clear();
        }

        return .Ok;
    }

    public static int Main(String[] args)
    {
        String filename = "output.txt";

        if (WriteFile(filename) case .Err)
        {
            Console.WriteLine($"Could not write {filename}");
        }

        if (ReadFile(filename) case .Err)
        {
            Console.WriteLine($"Could not read {filename}");
        }

        return 0;
    }
}

File Input Output in Beef was written by:

If you see anything you'd like to change or update, please consider contributing.

How to Implement the Solution

No 'How to Implement the Solution' section available. Please consider contributing.

How to Run the Solution

No 'How to Run the Solution' section available. Please consider contributing.