In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly introduces "the method and function of random reading and writing of files in C++". In daily operation, I believe many people have doubts about the method and function of random reading and writing of documents in C++. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts about "the introduction of random reading and writing methods and their functions of documents in C++". Next, please follow the editor to study!
Catalogue
Overview
Random read and write
Function
Examples
Pointer stream member function
Random access to binary data
Overview
The operation of files can be divided into sequential reading and writing and random reading and writing. Sequential read and write means that the pointer to a file can only be moved from head to tail. Random read and write means that the file pointer can be moved at will as needed.
Random read and write
File pointer: in a disk file operation, there is a file pointer that indicates where to read and write.
Function
The file stream provides some member functions about file pointers:
The member function functions gcount () to return the number of bytes read in the last input tellg () returns the current position of the input file pointer seekg (location in the file) moves the pointer in the input file to the specified location seekg (displacement) Tellp () returns the current position of the output file pointer seekp (location in the file) moves the pointer in the output file to the specified location seekp (displacement, reference position) moves several bytes based on the reference position
G-for input functions (get), such as seekg for output files
P-for output functions (put), such as seekp for output files
Other-can both input and output files, any messenger two sets of functions.
Examples
Enter 10 integers from the keyboard and save them to the data file F1. In dat, read the data from the file and display it on the screen.
# include # include using namespace std;int main () {int a [10], b [10]; / / Open the file fstream iofile ("temp.txt", ios::in | ios::out); if (! iofile) {cerr
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 268
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.