Python

  1. with open("log.txt") as infile:
  2. for line in infile:
  3. do_something_with(line)

C

  1. #include <stdio.h>
  2. main()
  3. {
  4. FILE *fp;
  5. fp = fopen("/tmp/test.txt", "w+");
  6. fprintf(fp, "This is testing for fprintf ...\n");
  7. fputs("This is testing for fputs...\n", fp);
  8. fclose(fp);
  9. }

C++

  1. #include <iostream>
  2. #include <fstream>
  3. using namespace std;
  4. int main()
  5. {
  6. ofstream MyFile("filename.txt");
  7. MyFile << "Files can be tricky, but it is fun enough!";
  8. MyFile.close();
  9. }