- File represents storage media for storing data/information.
- Streams refer to sequence of bytes.
- In Files we can store data i.e. text or binary data permanently and use these data to read or write in the form of input output operations by transferring bytes of data. So we use the term File Streams(File handling).
We have to use the header file fstream
- till today, we have been using the iostream standard library, which provides cin and cout methods for reading from standard input and writing to standard output respectively.
- to read and write from a file, this requires another standard C++ library called fstream, which defines three new data types −
- ofstream
This data type represents the output file stream and is used to create files and to write information to files.
- ifstream
This data type represents the input file stream and is used to read information from files.
- fstream
This data type represents the file stream generally, and has the capabilities of both ofstream and ifstream which means it can create files, write information to files, and read information from files.
To perform file processing in C++, header files iostream and fstream must be included in your C++ source file.
- creating a file
- opening a file
- write content to a file
- reading content
- updating
- closing
#Creating/opening a file:
if(!fs){
cout "
Creating file is failed ";
}else{
cout "
File Creation is successful ";
}
//close
fs.close();
getchar();
return 0;
}
5 сен 2024