close
close file
int ires = ts_file(Int iFileDescr,"close");
Here: iFileDescr - file object descriptor. Returns 0 if the file was closed successfully.
Example.
Create a file "my_file.txt" on the "C:" drive in the root directory and write a few lines into it.
string filepath = "c:\\my_file.txt";
int iFileDescr;
object("create", "ts_file", iFileDescr); // create an object of type file in memory
// open a clean file for writing, if it does not exist, then create
int ires = ts_file(iFileDescr, "open", filepath, "create", "we");
if (ires != 0)
{
cout << "File could not be opened:" << filepath; // print to the message box
return;
}
ires = ts_file(iFileDescr, "write", "First line\nSecond line\n"); // write two lines to file
if (ires != 0)
{
cout << "Failed to write to file";
return;
}
ires = ts_file(iFileDescr, "write", "Third line"); // write the third line
ires = ts_file(iFileDescr, "close"); // close the file
object("delete", iFileDescr); // remove the file object from memory
cout << "Program termination \n";