View Problem

Read the contents of a file into a string

ExpandDiskEdit
ruby
file = File.new("Solution108.rb")
whole_file = file.read
ExpandDiskEdit
erlang
Text = readfile("Solution607.erl"),
ExpandDiskEdit
erlang
Text = readfile("Solution608.erl"),
DiskEdit
clojure
(slurp "/tmp/foobar")
ExpandDiskEdit
cpp C++/CLI .NET 2.0
IO::FileStream^ file; String^ buffer;

try
{
file = gcnew IO::FileStream("test.txt", IO::FileMode::Open);
buffer = gcnew String((gcnew IO::BinaryReader(file))->ReadChars(file->Length));
}
ExpandDiskEdit
cpp C++/CLI .NET 2.0
IO::StreamReader^ stream; String^ buffer;

try
{
stream = gcnew IO::StreamReader("test.txt");
buffer = stream->ReadToEnd();
}
ExpandDiskEdit
cpp C++/CLI .NET 2.0
String^ buffer = IO::File::ReadAllText("test.txt");

Submit a new solution for ruby, erlang, clojure, or cpp
There are 16 other solutions in additional languages (csharp, fantom, fsharp, groovy ...)