
Swapping names is not so hard in C++; just read the names themselves into different variables then print them, as Bruce Merry did:
#include <string>
#include <fstream>
using namespace std;
int main() {
ifstream in ("names.in");
ofstream out ("names.out");
string first, last;
in >> first >> last;
out << last << ", " << first << "\n";
return 0;
}