// counter.cpp - C++ equivalent to counter.pl #include main() { // Read count from file ifstream in("counter.txt"); int count = 0; if (in) { in >> count; } in.close(); // Add 1 and save count = count + 1; ofstream out("counter.txt"); if (out) out << count << "\n"; out.close(); // Display the new count cout << count; }