Princeton's code uses the current standard header files and prefered namespace syntax to minimize exposure of members of namespace std. If you have an older compiler, this syntax won't work--and you might consider updating your compiler. To write to a file you can do something like this:

string filename;
std::getline(std::cin, filename);

//use the C style string in filename to associate file with ofstream
std:fstream fout(filename.c_str());

//check if association didn't work and file failed to open
if(!fout.is_open())
{
//send message to error log
std::cerr << "Error opening file for reading" << std::endl;

//exit function due to failure
return EXIT_FAILURE;
}

//else you are ready to write material to filename using fout. Material may be text or binary.

You may also use an fstream with a variety of flags to indicate intention to read or write to file if you don't want to use an ifstream to read file and an ofstream to write to file.

Just about every step in the above code has alternate syntax that could be used and still have valid code. However the priniciples of declaring a stream to use, associating a file with a stream, checking to be sure the association worked and the file is open for use, and then using the same syntax with the file stream as you would with cin/cout still holds.