Instruction
stringlengths
45
106
input_code
stringlengths
1
13.7k
output_code
stringlengths
1
13.7k
Produce a functionally identical C++ code for the snippet given in Mathematica.
Import["filename","String"]
#include <iostream> #include <fstream> #include <string> #include <iterator> int main( ) { if (std::ifstream infile("sample.txt")) { std::string fileData(std::istreambuf_iterator<char>(infile), std::istreambuf_iterator<char>()); cout << "File has " << fileData.size() << "chars\n"; return 0; } else { std::cout << "file not found!\n"; return 1; } }
Generate a VB translation of this Mathematica snippet without changing its computational steps.
Import["filename","String"]
dim s s = createobject("scripting.filesystemobject").opentextfile("slurp.vbs",1).readall wscript.echo s
Ensure the translated C code behaves exactly like the original MATLAB snippet.
fid = fopen('filename','r'); [str,count] = fread(fid, [1,inf], 'uint8=>char'); fclose(fid);
#include <stdio.h> #include <stdlib.h> int main() { char *buffer; FILE *fh = fopen("readentirefile.c", "rb"); if ( fh != NULL ) { fseek(fh, 0L, SEEK_END); long s = ftell(fh); rewind(fh); buffer = malloc(s); if ( buffer != NULL ) { fread(buffer, s, 1, fh); fclose(fh); fh = NULL; fwrite(buffer, s, 1, stdout); free(buffer); } if (fh != NULL) fclose(fh); } return EXIT_SUCCESS; }
Write a version of this MATLAB function in C# with identical behavior.
fid = fopen('filename','r'); [str,count] = fread(fid, [1,inf], 'uint8=>char'); fclose(fid);
using System.IO; class Program { static void Main(string[] args) { var fileContents = File.ReadAllText("c:\\autoexec.bat"); } }
Transform the following MATLAB implementation into C++, maintaining the same output and logic.
fid = fopen('filename','r'); [str,count] = fread(fid, [1,inf], 'uint8=>char'); fclose(fid);
#include <iostream> #include <fstream> #include <string> #include <iterator> int main( ) { if (std::ifstream infile("sample.txt")) { std::string fileData(std::istreambuf_iterator<char>(infile), std::istreambuf_iterator<char>()); cout << "File has " << fileData.size() << "chars\n"; return 0; } else { std::cout << "file not found!\n"; return 1; } }
Generate an equivalent Java version of this MATLAB code.
fid = fopen('filename','r'); [str,count] = fread(fid, [1,inf], 'uint8=>char'); fclose(fid);
static Byte[] contentsOf(File file) { return file.contents; }
Write the same code in Python as shown below in MATLAB.
fid = fopen('filename','r'); [str,count] = fread(fid, [1,inf], 'uint8=>char'); fclose(fid);
open(filename).read()
Produce a functionally identical VB code for the snippet given in MATLAB.
fid = fopen('filename','r'); [str,count] = fread(fid, [1,inf], 'uint8=>char'); fclose(fid);
dim s s = createobject("scripting.filesystemobject").opentextfile("slurp.vbs",1).readall wscript.echo s
Write the same code in Go as shown below in MATLAB.
fid = fopen('filename','r'); [str,count] = fread(fid, [1,inf], 'uint8=>char'); fclose(fid);
import "io/ioutil" data, err := ioutil.ReadFile(filename) sv := string(data)
Convert this Nim snippet to C and keep its semantics consistent.
readFile(filename)
#include <stdio.h> #include <stdlib.h> int main() { char *buffer; FILE *fh = fopen("readentirefile.c", "rb"); if ( fh != NULL ) { fseek(fh, 0L, SEEK_END); long s = ftell(fh); rewind(fh); buffer = malloc(s); if ( buffer != NULL ) { fread(buffer, s, 1, fh); fclose(fh); fh = NULL; fwrite(buffer, s, 1, stdout); free(buffer); } if (fh != NULL) fclose(fh); } return EXIT_SUCCESS; }
Port the following code from Nim to C# with equivalent syntax and logic.
readFile(filename)
using System.IO; class Program { static void Main(string[] args) { var fileContents = File.ReadAllText("c:\\autoexec.bat"); } }
Preserve the algorithm and functionality while converting the code from Nim to C++.
readFile(filename)
#include <iostream> #include <fstream> #include <string> #include <iterator> int main( ) { if (std::ifstream infile("sample.txt")) { std::string fileData(std::istreambuf_iterator<char>(infile), std::istreambuf_iterator<char>()); cout << "File has " << fileData.size() << "chars\n"; return 0; } else { std::cout << "file not found!\n"; return 1; } }
Generate a VB translation of this Nim snippet without changing its computational steps.
readFile(filename)
dim s s = createobject("scripting.filesystemobject").opentextfile("slurp.vbs",1).readall wscript.echo s
Write the same code in C as shown below in OCaml.
let load_file f = let ic = open_in f in let n = in_channel_length ic in let s = Bytes.create n in really_input ic s 0 n; close_in ic; (s)
#include <stdio.h> #include <stdlib.h> int main() { char *buffer; FILE *fh = fopen("readentirefile.c", "rb"); if ( fh != NULL ) { fseek(fh, 0L, SEEK_END); long s = ftell(fh); rewind(fh); buffer = malloc(s); if ( buffer != NULL ) { fread(buffer, s, 1, fh); fclose(fh); fh = NULL; fwrite(buffer, s, 1, stdout); free(buffer); } if (fh != NULL) fclose(fh); } return EXIT_SUCCESS; }
Rewrite the snippet below in C# so it works the same as the original OCaml code.
let load_file f = let ic = open_in f in let n = in_channel_length ic in let s = Bytes.create n in really_input ic s 0 n; close_in ic; (s)
using System.IO; class Program { static void Main(string[] args) { var fileContents = File.ReadAllText("c:\\autoexec.bat"); } }
Port the following code from OCaml to C++ with equivalent syntax and logic.
let load_file f = let ic = open_in f in let n = in_channel_length ic in let s = Bytes.create n in really_input ic s 0 n; close_in ic; (s)
#include <iostream> #include <fstream> #include <string> #include <iterator> int main( ) { if (std::ifstream infile("sample.txt")) { std::string fileData(std::istreambuf_iterator<char>(infile), std::istreambuf_iterator<char>()); cout << "File has " << fileData.size() << "chars\n"; return 0; } else { std::cout << "file not found!\n"; return 1; } }
Rewrite the snippet below in Java so it works the same as the original OCaml code.
let load_file f = let ic = open_in f in let n = in_channel_length ic in let s = Bytes.create n in really_input ic s 0 n; close_in ic; (s)
static Byte[] contentsOf(File file) { return file.contents; }
Write the same code in Python as shown below in OCaml.
let load_file f = let ic = open_in f in let n = in_channel_length ic in let s = Bytes.create n in really_input ic s 0 n; close_in ic; (s)
open(filename).read()
Maintain the same structure and functionality when rewriting this code in VB.
let load_file f = let ic = open_in f in let n = in_channel_length ic in let s = Bytes.create n in really_input ic s 0 n; close_in ic; (s)
dim s s = createobject("scripting.filesystemobject").opentextfile("slurp.vbs",1).readall wscript.echo s
Write the same code in Go as shown below in OCaml.
let load_file f = let ic = open_in f in let n = in_channel_length ic in let s = Bytes.create n in really_input ic s 0 n; close_in ic; (s)
import "io/ioutil" data, err := ioutil.ReadFile(filename) sv := string(data)
Translate this program into C but keep the logic exactly as in Perl.
use File::Slurper 'read_text'; my $text = read_text($filename, $data);
#include <stdio.h> #include <stdlib.h> int main() { char *buffer; FILE *fh = fopen("readentirefile.c", "rb"); if ( fh != NULL ) { fseek(fh, 0L, SEEK_END); long s = ftell(fh); rewind(fh); buffer = malloc(s); if ( buffer != NULL ) { fread(buffer, s, 1, fh); fclose(fh); fh = NULL; fwrite(buffer, s, 1, stdout); free(buffer); } if (fh != NULL) fclose(fh); } return EXIT_SUCCESS; }
Convert this Perl block to C#, preserving its control flow and logic.
use File::Slurper 'read_text'; my $text = read_text($filename, $data);
using System.IO; class Program { static void Main(string[] args) { var fileContents = File.ReadAllText("c:\\autoexec.bat"); } }
Write the same code in C++ as shown below in Perl.
use File::Slurper 'read_text'; my $text = read_text($filename, $data);
#include <iostream> #include <fstream> #include <string> #include <iterator> int main( ) { if (std::ifstream infile("sample.txt")) { std::string fileData(std::istreambuf_iterator<char>(infile), std::istreambuf_iterator<char>()); cout << "File has " << fileData.size() << "chars\n"; return 0; } else { std::cout << "file not found!\n"; return 1; } }
Write a version of this Perl function in Java with identical behavior.
use File::Slurper 'read_text'; my $text = read_text($filename, $data);
static Byte[] contentsOf(File file) { return file.contents; }
Can you help me rewrite this code in VB instead of Perl, keeping it the same logically?
use File::Slurper 'read_text'; my $text = read_text($filename, $data);
dim s s = createobject("scripting.filesystemobject").opentextfile("slurp.vbs",1).readall wscript.echo s
Produce a language-to-language conversion: from Perl to Go, same semantics.
use File::Slurper 'read_text'; my $text = read_text($filename, $data);
import "io/ioutil" data, err := ioutil.ReadFile(filename) sv := string(data)
Produce a language-to-language conversion: from PowerShell to C, same semantics.
Get-Content foo.txt
#include <stdio.h> #include <stdlib.h> int main() { char *buffer; FILE *fh = fopen("readentirefile.c", "rb"); if ( fh != NULL ) { fseek(fh, 0L, SEEK_END); long s = ftell(fh); rewind(fh); buffer = malloc(s); if ( buffer != NULL ) { fread(buffer, s, 1, fh); fclose(fh); fh = NULL; fwrite(buffer, s, 1, stdout); free(buffer); } if (fh != NULL) fclose(fh); } return EXIT_SUCCESS; }
Convert the following code from PowerShell to C#, ensuring the logic remains intact.
Get-Content foo.txt
using System.IO; class Program { static void Main(string[] args) { var fileContents = File.ReadAllText("c:\\autoexec.bat"); } }
Convert the following code from PowerShell to C++, ensuring the logic remains intact.
Get-Content foo.txt
#include <iostream> #include <fstream> #include <string> #include <iterator> int main( ) { if (std::ifstream infile("sample.txt")) { std::string fileData(std::istreambuf_iterator<char>(infile), std::istreambuf_iterator<char>()); cout << "File has " << fileData.size() << "chars\n"; return 0; } else { std::cout << "file not found!\n"; return 1; } }
Please provide an equivalent version of this PowerShell code in VB.
Get-Content foo.txt
dim s s = createobject("scripting.filesystemobject").opentextfile("slurp.vbs",1).readall wscript.echo s
Preserve the algorithm and functionality while converting the code from R to C.
fname <- "notes.txt" contents <- readChar(fname, file.info(fname)$size)
#include <stdio.h> #include <stdlib.h> int main() { char *buffer; FILE *fh = fopen("readentirefile.c", "rb"); if ( fh != NULL ) { fseek(fh, 0L, SEEK_END); long s = ftell(fh); rewind(fh); buffer = malloc(s); if ( buffer != NULL ) { fread(buffer, s, 1, fh); fclose(fh); fh = NULL; fwrite(buffer, s, 1, stdout); free(buffer); } if (fh != NULL) fclose(fh); } return EXIT_SUCCESS; }
Generate a C# translation of this R snippet without changing its computational steps.
fname <- "notes.txt" contents <- readChar(fname, file.info(fname)$size)
using System.IO; class Program { static void Main(string[] args) { var fileContents = File.ReadAllText("c:\\autoexec.bat"); } }
Ensure the translated C++ code behaves exactly like the original R snippet.
fname <- "notes.txt" contents <- readChar(fname, file.info(fname)$size)
#include <iostream> #include <fstream> #include <string> #include <iterator> int main( ) { if (std::ifstream infile("sample.txt")) { std::string fileData(std::istreambuf_iterator<char>(infile), std::istreambuf_iterator<char>()); cout << "File has " << fileData.size() << "chars\n"; return 0; } else { std::cout << "file not found!\n"; return 1; } }
Port the provided R code into Java while preserving the original functionality.
fname <- "notes.txt" contents <- readChar(fname, file.info(fname)$size)
static Byte[] contentsOf(File file) { return file.contents; }
Generate an equivalent VB version of this R code.
fname <- "notes.txt" contents <- readChar(fname, file.info(fname)$size)
dim s s = createobject("scripting.filesystemobject").opentextfile("slurp.vbs",1).readall wscript.echo s
Transform the following R implementation into Go, maintaining the same output and logic.
fname <- "notes.txt" contents <- readChar(fname, file.info(fname)$size)
import "io/ioutil" data, err := ioutil.ReadFile(filename) sv := string(data)
Please provide an equivalent version of this Racket code in C.
(file->string "foo.txt")
#include <stdio.h> #include <stdlib.h> int main() { char *buffer; FILE *fh = fopen("readentirefile.c", "rb"); if ( fh != NULL ) { fseek(fh, 0L, SEEK_END); long s = ftell(fh); rewind(fh); buffer = malloc(s); if ( buffer != NULL ) { fread(buffer, s, 1, fh); fclose(fh); fh = NULL; fwrite(buffer, s, 1, stdout); free(buffer); } if (fh != NULL) fclose(fh); } return EXIT_SUCCESS; }
Translate the given Racket code snippet into C# without altering its behavior.
(file->string "foo.txt")
using System.IO; class Program { static void Main(string[] args) { var fileContents = File.ReadAllText("c:\\autoexec.bat"); } }
Generate an equivalent C++ version of this Racket code.
(file->string "foo.txt")
#include <iostream> #include <fstream> #include <string> #include <iterator> int main( ) { if (std::ifstream infile("sample.txt")) { std::string fileData(std::istreambuf_iterator<char>(infile), std::istreambuf_iterator<char>()); cout << "File has " << fileData.size() << "chars\n"; return 0; } else { std::cout << "file not found!\n"; return 1; } }
Can you help me rewrite this code in VB instead of Racket, keeping it the same logically?
(file->string "foo.txt")
dim s s = createobject("scripting.filesystemobject").opentextfile("slurp.vbs",1).readall wscript.echo s
Produce a functionally identical C code for the snippet given in REXX.
options replace format comments java crossref symbols nobinary parse arg inFileName . if inFileName = '' | inFileName = '.' then inFileName = './data/dwarfs.json' fileContents = slurp(inFileName) say fileContents return -- Slurp a file and return contents as a Rexx string method slurp(inFileName) public static returns Rexx slurped = Rexx null slurpStr = StringBuilder() ioBuffer = byte[1024] inBytes = int 0 do inFile = File(inFileName) inFileIS = BufferedInputStream(FileInputStream(inFile)) loop label ioLoop until inBytes = -1 slurpStr.append(String(ioBuffer, 0, inBytes)) inBytes = inFileIS.read(ioBuffer) end ioLoop catch exFNF = FileNotFoundException exFNF.printStackTrace catch exIO = IOException exIO.printStackTrace finally do inFileIS.close() catch ex = IOException ex.printStackTrace end end slurped = Rexx(slurpStr.toString) return slurped
#include <stdio.h> #include <stdlib.h> int main() { char *buffer; FILE *fh = fopen("readentirefile.c", "rb"); if ( fh != NULL ) { fseek(fh, 0L, SEEK_END); long s = ftell(fh); rewind(fh); buffer = malloc(s); if ( buffer != NULL ) { fread(buffer, s, 1, fh); fclose(fh); fh = NULL; fwrite(buffer, s, 1, stdout); free(buffer); } if (fh != NULL) fclose(fh); } return EXIT_SUCCESS; }
Maintain the same structure and functionality when rewriting this code in C#.
options replace format comments java crossref symbols nobinary parse arg inFileName . if inFileName = '' | inFileName = '.' then inFileName = './data/dwarfs.json' fileContents = slurp(inFileName) say fileContents return -- Slurp a file and return contents as a Rexx string method slurp(inFileName) public static returns Rexx slurped = Rexx null slurpStr = StringBuilder() ioBuffer = byte[1024] inBytes = int 0 do inFile = File(inFileName) inFileIS = BufferedInputStream(FileInputStream(inFile)) loop label ioLoop until inBytes = -1 slurpStr.append(String(ioBuffer, 0, inBytes)) inBytes = inFileIS.read(ioBuffer) end ioLoop catch exFNF = FileNotFoundException exFNF.printStackTrace catch exIO = IOException exIO.printStackTrace finally do inFileIS.close() catch ex = IOException ex.printStackTrace end end slurped = Rexx(slurpStr.toString) return slurped
using System.IO; class Program { static void Main(string[] args) { var fileContents = File.ReadAllText("c:\\autoexec.bat"); } }
Produce a language-to-language conversion: from REXX to C++, same semantics.
options replace format comments java crossref symbols nobinary parse arg inFileName . if inFileName = '' | inFileName = '.' then inFileName = './data/dwarfs.json' fileContents = slurp(inFileName) say fileContents return -- Slurp a file and return contents as a Rexx string method slurp(inFileName) public static returns Rexx slurped = Rexx null slurpStr = StringBuilder() ioBuffer = byte[1024] inBytes = int 0 do inFile = File(inFileName) inFileIS = BufferedInputStream(FileInputStream(inFile)) loop label ioLoop until inBytes = -1 slurpStr.append(String(ioBuffer, 0, inBytes)) inBytes = inFileIS.read(ioBuffer) end ioLoop catch exFNF = FileNotFoundException exFNF.printStackTrace catch exIO = IOException exIO.printStackTrace finally do inFileIS.close() catch ex = IOException ex.printStackTrace end end slurped = Rexx(slurpStr.toString) return slurped
#include <iostream> #include <fstream> #include <string> #include <iterator> int main( ) { if (std::ifstream infile("sample.txt")) { std::string fileData(std::istreambuf_iterator<char>(infile), std::istreambuf_iterator<char>()); cout << "File has " << fileData.size() << "chars\n"; return 0; } else { std::cout << "file not found!\n"; return 1; } }
Rewrite the snippet below in Java so it works the same as the original REXX code.
options replace format comments java crossref symbols nobinary parse arg inFileName . if inFileName = '' | inFileName = '.' then inFileName = './data/dwarfs.json' fileContents = slurp(inFileName) say fileContents return -- Slurp a file and return contents as a Rexx string method slurp(inFileName) public static returns Rexx slurped = Rexx null slurpStr = StringBuilder() ioBuffer = byte[1024] inBytes = int 0 do inFile = File(inFileName) inFileIS = BufferedInputStream(FileInputStream(inFile)) loop label ioLoop until inBytes = -1 slurpStr.append(String(ioBuffer, 0, inBytes)) inBytes = inFileIS.read(ioBuffer) end ioLoop catch exFNF = FileNotFoundException exFNF.printStackTrace catch exIO = IOException exIO.printStackTrace finally do inFileIS.close() catch ex = IOException ex.printStackTrace end end slurped = Rexx(slurpStr.toString) return slurped
static Byte[] contentsOf(File file) { return file.contents; }
Please provide an equivalent version of this REXX code in Python.
options replace format comments java crossref symbols nobinary parse arg inFileName . if inFileName = '' | inFileName = '.' then inFileName = './data/dwarfs.json' fileContents = slurp(inFileName) say fileContents return -- Slurp a file and return contents as a Rexx string method slurp(inFileName) public static returns Rexx slurped = Rexx null slurpStr = StringBuilder() ioBuffer = byte[1024] inBytes = int 0 do inFile = File(inFileName) inFileIS = BufferedInputStream(FileInputStream(inFile)) loop label ioLoop until inBytes = -1 slurpStr.append(String(ioBuffer, 0, inBytes)) inBytes = inFileIS.read(ioBuffer) end ioLoop catch exFNF = FileNotFoundException exFNF.printStackTrace catch exIO = IOException exIO.printStackTrace finally do inFileIS.close() catch ex = IOException ex.printStackTrace end end slurped = Rexx(slurpStr.toString) return slurped
open(filename).read()
Keep all operations the same but rewrite the snippet in VB.
options replace format comments java crossref symbols nobinary parse arg inFileName . if inFileName = '' | inFileName = '.' then inFileName = './data/dwarfs.json' fileContents = slurp(inFileName) say fileContents return -- Slurp a file and return contents as a Rexx string method slurp(inFileName) public static returns Rexx slurped = Rexx null slurpStr = StringBuilder() ioBuffer = byte[1024] inBytes = int 0 do inFile = File(inFileName) inFileIS = BufferedInputStream(FileInputStream(inFile)) loop label ioLoop until inBytes = -1 slurpStr.append(String(ioBuffer, 0, inBytes)) inBytes = inFileIS.read(ioBuffer) end ioLoop catch exFNF = FileNotFoundException exFNF.printStackTrace catch exIO = IOException exIO.printStackTrace finally do inFileIS.close() catch ex = IOException ex.printStackTrace end end slurped = Rexx(slurpStr.toString) return slurped
dim s s = createobject("scripting.filesystemobject").opentextfile("slurp.vbs",1).readall wscript.echo s
Translate the given REXX code snippet into Go without altering its behavior.
options replace format comments java crossref symbols nobinary parse arg inFileName . if inFileName = '' | inFileName = '.' then inFileName = './data/dwarfs.json' fileContents = slurp(inFileName) say fileContents return -- Slurp a file and return contents as a Rexx string method slurp(inFileName) public static returns Rexx slurped = Rexx null slurpStr = StringBuilder() ioBuffer = byte[1024] inBytes = int 0 do inFile = File(inFileName) inFileIS = BufferedInputStream(FileInputStream(inFile)) loop label ioLoop until inBytes = -1 slurpStr.append(String(ioBuffer, 0, inBytes)) inBytes = inFileIS.read(ioBuffer) end ioLoop catch exFNF = FileNotFoundException exFNF.printStackTrace catch exIO = IOException exIO.printStackTrace finally do inFileIS.close() catch ex = IOException ex.printStackTrace end end slurped = Rexx(slurpStr.toString) return slurped
import "io/ioutil" data, err := ioutil.ReadFile(filename) sv := string(data)
Produce a language-to-language conversion: from Ruby to C, same semantics.
content = File.read("input.txt") puts content
#include <stdio.h> #include <stdlib.h> int main() { char *buffer; FILE *fh = fopen("readentirefile.c", "rb"); if ( fh != NULL ) { fseek(fh, 0L, SEEK_END); long s = ftell(fh); rewind(fh); buffer = malloc(s); if ( buffer != NULL ) { fread(buffer, s, 1, fh); fclose(fh); fh = NULL; fwrite(buffer, s, 1, stdout); free(buffer); } if (fh != NULL) fclose(fh); } return EXIT_SUCCESS; }
Port the provided Ruby code into C# while preserving the original functionality.
content = File.read("input.txt") puts content
using System.IO; class Program { static void Main(string[] args) { var fileContents = File.ReadAllText("c:\\autoexec.bat"); } }
Rewrite this program in C++ while keeping its functionality equivalent to the Ruby version.
content = File.read("input.txt") puts content
#include <iostream> #include <fstream> #include <string> #include <iterator> int main( ) { if (std::ifstream infile("sample.txt")) { std::string fileData(std::istreambuf_iterator<char>(infile), std::istreambuf_iterator<char>()); cout << "File has " << fileData.size() << "chars\n"; return 0; } else { std::cout << "file not found!\n"; return 1; } }
Port the following code from Ruby to VB with equivalent syntax and logic.
content = File.read("input.txt") puts content
dim s s = createobject("scripting.filesystemobject").opentextfile("slurp.vbs",1).readall wscript.echo s
Write a version of this Ruby function in Go with identical behavior.
content = File.read("input.txt") puts content
import "io/ioutil" data, err := ioutil.ReadFile(filename) sv := string(data)
Rewrite this program in C while keeping its functionality equivalent to the Scala version.
import java.io.File fun main(args: Array<String>) { println(File("unixdict.txt").readText(charset = Charsets.UTF_8)) }
#include <stdio.h> #include <stdlib.h> int main() { char *buffer; FILE *fh = fopen("readentirefile.c", "rb"); if ( fh != NULL ) { fseek(fh, 0L, SEEK_END); long s = ftell(fh); rewind(fh); buffer = malloc(s); if ( buffer != NULL ) { fread(buffer, s, 1, fh); fclose(fh); fh = NULL; fwrite(buffer, s, 1, stdout); free(buffer); } if (fh != NULL) fclose(fh); } return EXIT_SUCCESS; }
Produce a functionally identical C# code for the snippet given in Scala.
import java.io.File fun main(args: Array<String>) { println(File("unixdict.txt").readText(charset = Charsets.UTF_8)) }
using System.IO; class Program { static void Main(string[] args) { var fileContents = File.ReadAllText("c:\\autoexec.bat"); } }
Translate the given Scala code snippet into C++ without altering its behavior.
import java.io.File fun main(args: Array<String>) { println(File("unixdict.txt").readText(charset = Charsets.UTF_8)) }
#include <iostream> #include <fstream> #include <string> #include <iterator> int main( ) { if (std::ifstream infile("sample.txt")) { std::string fileData(std::istreambuf_iterator<char>(infile), std::istreambuf_iterator<char>()); cout << "File has " << fileData.size() << "chars\n"; return 0; } else { std::cout << "file not found!\n"; return 1; } }
Produce a language-to-language conversion: from Scala to Java, same semantics.
import java.io.File fun main(args: Array<String>) { println(File("unixdict.txt").readText(charset = Charsets.UTF_8)) }
static Byte[] contentsOf(File file) { return file.contents; }
Preserve the algorithm and functionality while converting the code from Scala to Python.
import java.io.File fun main(args: Array<String>) { println(File("unixdict.txt").readText(charset = Charsets.UTF_8)) }
open(filename).read()
Convert this Scala block to VB, preserving its control flow and logic.
import java.io.File fun main(args: Array<String>) { println(File("unixdict.txt").readText(charset = Charsets.UTF_8)) }
dim s s = createobject("scripting.filesystemobject").opentextfile("slurp.vbs",1).readall wscript.echo s
Convert the following code from Scala to Go, ensuring the logic remains intact.
import java.io.File fun main(args: Array<String>) { println(File("unixdict.txt").readText(charset = Charsets.UTF_8)) }
import "io/ioutil" data, err := ioutil.ReadFile(filename) sv := string(data)
Convert the following code from Swift to C, ensuring the logic remains intact.
import Foundation let path = "~/input.txt".stringByExpandingTildeInPath if let string = String(contentsOfFile: path, encoding: NSUTF8StringEncoding) { println(string) }
#include <stdio.h> #include <stdlib.h> int main() { char *buffer; FILE *fh = fopen("readentirefile.c", "rb"); if ( fh != NULL ) { fseek(fh, 0L, SEEK_END); long s = ftell(fh); rewind(fh); buffer = malloc(s); if ( buffer != NULL ) { fread(buffer, s, 1, fh); fclose(fh); fh = NULL; fwrite(buffer, s, 1, stdout); free(buffer); } if (fh != NULL) fclose(fh); } return EXIT_SUCCESS; }
Port the provided Swift code into C# while preserving the original functionality.
import Foundation let path = "~/input.txt".stringByExpandingTildeInPath if let string = String(contentsOfFile: path, encoding: NSUTF8StringEncoding) { println(string) }
using System.IO; class Program { static void Main(string[] args) { var fileContents = File.ReadAllText("c:\\autoexec.bat"); } }
Write the same code in C++ as shown below in Swift.
import Foundation let path = "~/input.txt".stringByExpandingTildeInPath if let string = String(contentsOfFile: path, encoding: NSUTF8StringEncoding) { println(string) }
#include <iostream> #include <fstream> #include <string> #include <iterator> int main( ) { if (std::ifstream infile("sample.txt")) { std::string fileData(std::istreambuf_iterator<char>(infile), std::istreambuf_iterator<char>()); cout << "File has " << fileData.size() << "chars\n"; return 0; } else { std::cout << "file not found!\n"; return 1; } }
Rewrite this program in Java while keeping its functionality equivalent to the Swift version.
import Foundation let path = "~/input.txt".stringByExpandingTildeInPath if let string = String(contentsOfFile: path, encoding: NSUTF8StringEncoding) { println(string) }
static Byte[] contentsOf(File file) { return file.contents; }
Maintain the same structure and functionality when rewriting this code in Python.
import Foundation let path = "~/input.txt".stringByExpandingTildeInPath if let string = String(contentsOfFile: path, encoding: NSUTF8StringEncoding) { println(string) }
open(filename).read()
Ensure the translated VB code behaves exactly like the original Swift snippet.
import Foundation let path = "~/input.txt".stringByExpandingTildeInPath if let string = String(contentsOfFile: path, encoding: NSUTF8StringEncoding) { println(string) }
dim s s = createobject("scripting.filesystemobject").opentextfile("slurp.vbs",1).readall wscript.echo s
Produce a language-to-language conversion: from Swift to Go, same semantics.
import Foundation let path = "~/input.txt".stringByExpandingTildeInPath if let string = String(contentsOfFile: path, encoding: NSUTF8StringEncoding) { println(string) }
import "io/ioutil" data, err := ioutil.ReadFile(filename) sv := string(data)
Ensure the translated C code behaves exactly like the original Tcl snippet.
set f [open $filename] set data [read $f] close $f
#include <stdio.h> #include <stdlib.h> int main() { char *buffer; FILE *fh = fopen("readentirefile.c", "rb"); if ( fh != NULL ) { fseek(fh, 0L, SEEK_END); long s = ftell(fh); rewind(fh); buffer = malloc(s); if ( buffer != NULL ) { fread(buffer, s, 1, fh); fclose(fh); fh = NULL; fwrite(buffer, s, 1, stdout); free(buffer); } if (fh != NULL) fclose(fh); } return EXIT_SUCCESS; }
Generate an equivalent C# version of this Tcl code.
set f [open $filename] set data [read $f] close $f
using System.IO; class Program { static void Main(string[] args) { var fileContents = File.ReadAllText("c:\\autoexec.bat"); } }
Translate this program into C++ but keep the logic exactly as in Tcl.
set f [open $filename] set data [read $f] close $f
#include <iostream> #include <fstream> #include <string> #include <iterator> int main( ) { if (std::ifstream infile("sample.txt")) { std::string fileData(std::istreambuf_iterator<char>(infile), std::istreambuf_iterator<char>()); cout << "File has " << fileData.size() << "chars\n"; return 0; } else { std::cout << "file not found!\n"; return 1; } }
Ensure the translated Java code behaves exactly like the original Tcl snippet.
set f [open $filename] set data [read $f] close $f
static Byte[] contentsOf(File file) { return file.contents; }
Please provide an equivalent version of this Tcl code in VB.
set f [open $filename] set data [read $f] close $f
dim s s = createobject("scripting.filesystemobject").opentextfile("slurp.vbs",1).readall wscript.echo s
Convert the following code from Tcl to Go, ensuring the logic remains intact.
set f [open $filename] set data [read $f] close $f
import "io/ioutil" data, err := ioutil.ReadFile(filename) sv := string(data)
Write a version of this Rust function in PHP with identical behavior.
use std::fs::File; use std::io::Read; fn main() { let mut file = File::open("somefile.txt").unwrap(); let mut contents: Vec<u8> = Vec::new(); let result = file.read_to_end(&mut contents).unwrap(); println!("Read {} bytes", result); let filestr = String::from_utf8(contents).unwrap(); println!("{}", filestr); }
file_get_contents($filename)
Change the following Ada code into PHP without altering its purpose.
with Ada.Directories, Ada.Direct_IO, Ada.Text_IO; procedure Whole_File is File_Name : String := "whole_file.adb"; File_Size : Natural := Natural (Ada.Directories.Size (File_Name)); subtype File_String is String (1 .. File_Size); package File_String_IO is new Ada.Direct_IO (File_String); File : File_String_IO.File_Type; Contents : File_String; begin File_String_IO.Open (File, Mode => File_String_IO.In_File, Name => File_Name); File_String_IO.Read (File, Item => Contents); File_String_IO.Close (File); Ada.Text_IO.Put (Contents); end Whole_File;
file_get_contents($filename)
Port the provided AWK code into PHP while preserving the original functionality.
BEGIN { RS=""; getline; print "=== line "NR,":",$0; } { print "=== line "NR,":",$0; }
file_get_contents($filename)
Preserve the algorithm and functionality while converting the code from BBC_Basic to PHP.
file% = OPENIN("input.txt") strvar$ = "" WHILE NOT EOF#file% strvar$ += CHR$(BGET#file%) ENDWHILE CLOSE #file%
file_get_contents($filename)
Rewrite the snippet below in PHP so it works the same as the original Clojure code.
(slurp "myfile.txt") (slurp "my-utf8-file.txt" "UTF-8")
file_get_contents($filename)
Ensure the translated PHP code behaves exactly like the original Common_Lisp snippet.
(defun file-string (path) (with-open-file (stream path) (let ((data (make-string (file-length stream)))) (read-sequence data stream) data)))
file_get_contents($filename)
Change the following D code into PHP without altering its purpose.
import std.file: read, readText; void main() { auto data = cast(ubyte[])read("unixdict.txt"); string txt = readText("unixdict.txt"); }
file_get_contents($filename)
Rewrite this program in PHP while keeping its functionality equivalent to the Delphi version.
program ReadAll; uses Classes; var i: Integer; lList: TStringList; begin lList := TStringList.Create; try lList.LoadFromFile('c:\input.txt'); Writeln(lList.Text); for i := 0 to lList.Count - 1 do Writeln(lList[i]); finally lList.Free; end; end.
file_get_contents($filename)
Convert the following code from Elixir to PHP, ensuring the logic remains intact.
defmodule FileReader do def read(path) do case File.read(path) do {:ok, body} -> IO.inspect body {:error,reason} -> :file.format_error(reason) end end def bit_read(path) do case File.open(path) do {:ok, file} -> IO.read(file,:all) |> IO.inspect {:error,reason} -> :file.format_error(reason) end end end
file_get_contents($filename)
Write a version of this F# function in PHP with identical behavior.
open System.IO let data = File.ReadAllText(filename) let utf8 = File.ReadAllText(filename, System.Text.Encoding.UTF8)
file_get_contents($filename)
Change the following Factor code into PHP without altering its purpose.
USING: io.encodings.ascii io.encodings.binary io.files ; "foo.txt" binary file-contents "foo.txt" ascii file-lines
file_get_contents($filename)
Convert this Fortran snippet to PHP and keep its semantics consistent.
program read_file implicit none integer :: n character(:), allocatable :: s open(unit=10, file="read_file.f90", action="read", & form="unformatted", access="stream") inquire(unit=10, size=n) allocate(character(n) :: s) read(10) s close(10) print "(A)", s end program
file_get_contents($filename)
Change the following Lua code into PHP without altering its purpose.
local file = assert(io.open(filename)) local contents = file:read'*a' file:close()
file_get_contents($filename)
Produce a language-to-language conversion: from MATLAB to PHP, same semantics.
fid = fopen('filename','r'); [str,count] = fread(fid, [1,inf], 'uint8=>char'); fclose(fid);
file_get_contents($filename)
Rewrite the snippet below in PHP so it works the same as the original OCaml code.
let load_file f = let ic = open_in f in let n = in_channel_length ic in let s = Bytes.create n in really_input ic s 0 n; close_in ic; (s)
file_get_contents($filename)
Translate this program into PHP but keep the logic exactly as in REXX.
options replace format comments java crossref symbols nobinary parse arg inFileName . if inFileName = '' | inFileName = '.' then inFileName = './data/dwarfs.json' fileContents = slurp(inFileName) say fileContents return -- Slurp a file and return contents as a Rexx string method slurp(inFileName) public static returns Rexx slurped = Rexx null slurpStr = StringBuilder() ioBuffer = byte[1024] inBytes = int 0 do inFile = File(inFileName) inFileIS = BufferedInputStream(FileInputStream(inFile)) loop label ioLoop until inBytes = -1 slurpStr.append(String(ioBuffer, 0, inBytes)) inBytes = inFileIS.read(ioBuffer) end ioLoop catch exFNF = FileNotFoundException exFNF.printStackTrace catch exIO = IOException exIO.printStackTrace finally do inFileIS.close() catch ex = IOException ex.printStackTrace end end slurped = Rexx(slurpStr.toString) return slurped
file_get_contents($filename)
Produce a functionally identical PHP code for the snippet given in Scala.
import java.io.File fun main(args: Array<String>) { println(File("unixdict.txt").readText(charset = Charsets.UTF_8)) }
file_get_contents($filename)
Maintain the same structure and functionality when rewriting this code in PHP.
import Foundation let path = "~/input.txt".stringByExpandingTildeInPath if let string = String(contentsOfFile: path, encoding: NSUTF8StringEncoding) { println(string) }
file_get_contents($filename)
Port the provided C++ code into Rust while preserving the original functionality.
#include <iostream> #include <fstream> #include <string> #include <iterator> int main( ) { if (std::ifstream infile("sample.txt")) { std::string fileData(std::istreambuf_iterator<char>(infile), std::istreambuf_iterator<char>()); cout << "File has " << fileData.size() << "chars\n"; return 0; } else { std::cout << "file not found!\n"; return 1; } }
use std::fs::File; use std::io::Read; fn main() { let mut file = File::open("somefile.txt").unwrap(); let mut contents: Vec<u8> = Vec::new(); let result = file.read_to_end(&mut contents).unwrap(); println!("Read {} bytes", result); let filestr = String::from_utf8(contents).unwrap(); println!("{}", filestr); }
Preserve the algorithm and functionality while converting the code from C# to Rust.
using System.IO; class Program { static void Main(string[] args) { var fileContents = File.ReadAllText("c:\\autoexec.bat"); } }
use std::fs::File; use std::io::Read; fn main() { let mut file = File::open("somefile.txt").unwrap(); let mut contents: Vec<u8> = Vec::new(); let result = file.read_to_end(&mut contents).unwrap(); println!("Read {} bytes", result); let filestr = String::from_utf8(contents).unwrap(); println!("{}", filestr); }
Write the same algorithm in Rust as shown in this Java implementation.
static Byte[] contentsOf(File file) { return file.contents; }
use std::fs::File; use std::io::Read; fn main() { let mut file = File::open("somefile.txt").unwrap(); let mut contents: Vec<u8> = Vec::new(); let result = file.read_to_end(&mut contents).unwrap(); println!("Read {} bytes", result); let filestr = String::from_utf8(contents).unwrap(); println!("{}", filestr); }
Convert the following code from Rust to VB, ensuring the logic remains intact.
use std::fs::File; use std::io::Read; fn main() { let mut file = File::open("somefile.txt").unwrap(); let mut contents: Vec<u8> = Vec::new(); let result = file.read_to_end(&mut contents).unwrap(); println!("Read {} bytes", result); let filestr = String::from_utf8(contents).unwrap(); println!("{}", filestr); }
dim s s = createobject("scripting.filesystemobject").opentextfile("slurp.vbs",1).readall wscript.echo s
Ensure the translated Rust code behaves exactly like the original Go snippet.
import "io/ioutil" data, err := ioutil.ReadFile(filename) sv := string(data)
use std::fs::File; use std::io::Read; fn main() { let mut file = File::open("somefile.txt").unwrap(); let mut contents: Vec<u8> = Vec::new(); let result = file.read_to_end(&mut contents).unwrap(); println!("Read {} bytes", result); let filestr = String::from_utf8(contents).unwrap(); println!("{}", filestr); }
Transform the following C implementation into Rust, maintaining the same output and logic.
#include <stdio.h> #include <stdlib.h> int main() { char *buffer; FILE *fh = fopen("readentirefile.c", "rb"); if ( fh != NULL ) { fseek(fh, 0L, SEEK_END); long s = ftell(fh); rewind(fh); buffer = malloc(s); if ( buffer != NULL ) { fread(buffer, s, 1, fh); fclose(fh); fh = NULL; fwrite(buffer, s, 1, stdout); free(buffer); } if (fh != NULL) fclose(fh); } return EXIT_SUCCESS; }
use std::fs::File; use std::io::Read; fn main() { let mut file = File::open("somefile.txt").unwrap(); let mut contents: Vec<u8> = Vec::new(); let result = file.read_to_end(&mut contents).unwrap(); println!("Read {} bytes", result); let filestr = String::from_utf8(contents).unwrap(); println!("{}", filestr); }
Write a version of this Rust function in Python with identical behavior.
use std::fs::File; use std::io::Read; fn main() { let mut file = File::open("somefile.txt").unwrap(); let mut contents: Vec<u8> = Vec::new(); let result = file.read_to_end(&mut contents).unwrap(); println!("Read {} bytes", result); let filestr = String::from_utf8(contents).unwrap(); println!("{}", filestr); }
open(filename).read()
Port the provided Ada code into C# while preserving the original functionality.
pragma Initialize_Scalars; with Ada.Text_IO; use Ada.Text_IO; procedure Invalid_Value is type Color is (Red, Green, Blue); X : Float; Y : Color; begin if not X'Valid then Put_Line ("X is not valid"); end if; X := 1.0; if X'Valid then Put_Line ("X is" & Float'Image (X)); end if; if not Y'Valid then Put_Line ("Y is not valid"); end if; Y := Green; if Y'Valid then Put_Line ("Y is " & Color'Image (Y)); end if; end Invalid_Value;
string foo = null;
Transform the following Ada implementation into C, maintaining the same output and logic.
pragma Initialize_Scalars; with Ada.Text_IO; use Ada.Text_IO; procedure Invalid_Value is type Color is (Red, Green, Blue); X : Float; Y : Color; begin if not X'Valid then Put_Line ("X is not valid"); end if; X := 1.0; if X'Valid then Put_Line ("X is" & Float'Image (X)); end if; if not Y'Valid then Put_Line ("Y is not valid"); end if; Y := Green; if Y'Valid then Put_Line ("Y is " & Color'Image (Y)); end if; end Invalid_Value;
#include <stdio.h> #include <stdlib.h> int main() { int junk, *junkp; printf("junk: %d\n", junk); junkp = malloc(sizeof *junkp); if (junkp) printf("*junkp: %d\n", *junkp); return 0; }
Rewrite this program in C++ while keeping its functionality equivalent to the Ada version.
pragma Initialize_Scalars; with Ada.Text_IO; use Ada.Text_IO; procedure Invalid_Value is type Color is (Red, Green, Blue); X : Float; Y : Color; begin if not X'Valid then Put_Line ("X is not valid"); end if; X := 1.0; if X'Valid then Put_Line ("X is" & Float'Image (X)); end if; if not Y'Valid then Put_Line ("Y is not valid"); end if; Y := Green; if Y'Valid then Put_Line ("Y is " & Color'Image (Y)); end if; end Invalid_Value;
#include <iostream> int main() { int undefined; if (undefined == 42) { std::cout << "42"; } if (undefined != 42) { std::cout << "not 42"; } }