We can print to a file in essentially the same way we print to the screen. In the simplest case, we create the entire file with one command; we give the file name as the initial left hand operand of <<, and we close the file with close. Files must be closed before they can be used for something else.
i1 : "testfile" << 2^100 << endl << close |
i2 : value get "testfile" |
More complicated files may require printing to the file multiple times. One way to handle this is to assign the open file created the first time we use << to a variable, so we can use it for subsequent print operations and for closing the file.
i3 : f = "testfile" << "" |
i4 : f << "hi" << endl |
i5 : f << "ho" << endl |
i6 : f << close |
i7 : get "testfile" |