fopen in various languages (file input/output

ofstream outfile(“out.txt”);
ifstream infile (“in.txt”); // class template

FILE * pFile = fopen (“myfile.txt”,”w”);

–php follows C
$handle = fopen(“a.txt”, “r”);

— python:
outfile = open(“a.txt”, “w”) # semicolon is usually omitted

open (OUTFILE, “>>append.txt”) or die …  ### No dollar sign. parentheses are optional but help readability

–c# offers many convenient solutions —
TextReader rd = new StreamReader(“in.txt”);
TextWriter tw = new StreamWrioter(“out.txt”);

Alternatively, File class offers variations of
static string ReadAllText(string path)
static void WriteAllText(string path, string contents) //creates or overwrites file

I have written so many of them but paradoxically can’t recall which class we need to instantiate


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s