Original collection
// AWZZZ @ 2002
// Getting Started -> Using (C Library) FSTREAM Read and write
// APO-> Using Fstream.
// Accident Project of use FStream. (C iostream library)
/ *
Reference: http://www.cplusplus.com/ref/iostream/fstream/
Description
FSTREAM CLASS Provides a stream interface to read and write data from / to files.
THE CLASS MANTAINS INTERNALLY (Privately) a Pointer to a filebuf Object in Charge
Of the interaction with the file. this pointer can be obtained / modified by calling
MEMBER RDBUF.
The file to be processed can be specified as a parameter for the constructor or by
Calling member open.
After A File Is Processed It Can Be Closed By Calling Member Close. In this case
The File Stream May BE Used to Open Another File.
MEMBER IS_OPEN CAN BE Used to Determine Wether The Stream IS Currently Operating
ON a file or not.
Please refer to Parent Classes for more details on information mantained by an
FSTREAM Object.
* /
// Use (C ) FSTREAM read and write files
// Simple Example
#include
#include
Using namespace std;
#ifdef Win32
#define test_file "c: //tmp/test.txt"
#ELSE
#define test_file "/tmp/test.txt"
#ENDIF
Void test ()
{
{
// fStream SFS;
//sfs.open (Test_File, iOS_BASE :: OUT);
FSTREAM SFS (Test_file, iOS_BASE :: OUT);
CHAR BUF [] = "1234567890";
Sfs.write (buf, sizeof (buf));
sfs.close ();
}
{
Int Len;
CHAR * BUF;
// fStream SFS;
//sfs.open (Test_File);
FStream SFS (Test_file);
sfs.seekg (0, ios :: end);
Len = sfs.tellg ();
Sfs.seekg (0, ios :: beg);
BUF = New char [len];
SFS.READ (BUF, LEN);
Cout << BUF << Endl;
DELETE [] BUF;
sfs.close ();
}
}
Int main (int Argc, char * argv [])
{
Test ();
Return 0;
}