C++ Tutorials - C++ File Processing
C++ File Streaming
File Processing in C++
File processing in C++ is performed using thefstream class. Unlike the FILE structure, fstream is a complete C++ class with constructors, a destructor and overloaded operators. To perform file processing, you can declare an instance of an fstreamobject. If you do not yet know the name of the file you want to process, you can use the default constructor. Unlike the FILE structure, the fstream class provides two distinct classes for fileprocessing. One is used to write to a file and the other is used to read from a file.
Initializing a File
When processing a file, you will typically specify the type of operation you want to perform.The operation is specified using what is referred to as a file mode. It can be one of the following: Mode ios::app Description If FileName is a new file, data is written to it. If FileName alreadyexists and contains data, then it is opened, the compiler goes to the end of the file and adds the new data to it. If FileName is a new file, data is written to it and subsequently added to the end of thefile. If FileName already exists and contains data, then it is opened and data is written in the current position. If FileName is a new file, then it gets created fine as an empty file. If FileNamealready exists, then it is opened and its content is made available for processing If FileName is a new file, then it gets created fine as an empty file. Once/Since it gets created empty, you can writedata to it. If FileName already exists, then it is opened, its content is destroyed, and the file becomes as new. Therefore you can create new data to write to it. Then, if you save the file, whichis the main purpose of this mode, the new content is saved it.*This operation is typically used when you want to save a file If FileName already exists, its content is destroyed and the file becomes...
Leer documento completo
Regístrate para leer el documento completo.