The seekp(pos) method of ostream in C++ is used to set the position of the pointer in the output sequence with the specified position. This method takes the new position to be set and returns this ostream instance with the position set to the specified new position.
ostream& seekp(streampos pos);
Parameter: This method takes the new position to be set as the parameter.
Return Value: This method returns this ostream instance with the position set to the specified new position.
Excpetions: If the operation sets an internal state flag (except eofbit) that was registered with member exceptions, the function throws an exception of member type failure.
Below examples demonstrate the use of seekp() method in C++:
Example 1: To show the use of seekp() with Binary file
- Take the input from the user about the serial number of the record to be displayed
- Pass n to the function then open the file in reading mode
- Place the write pointer at the starting of record by seekp((n-1)*Sizeof (object))
- Write the record to the file and then close it
- Open the file read the data and then close the file
size of record: 24 record no 1 (position int file 0) rno: 1 name: geek
Don’t stop now and take your learning to the next level. Learn all the important concepts of Data Structures and Algorithms with the help of the most trusted course: DSA Self Paced. Become industry ready at a student-friendly price.
- std::uniform_real_distribution a() method in C++ with Examples
- std::uniform_real_distribution max() method in C++ with Examples
- std::uniform_real_distribution min() method in C++ with Examples
- std::uniform_real_distribution b() method in C++ with Examples
- multiset value_comp() method in C++ STL
- std::uniform_int_distribution max() method in C++ with examples
- std::uniform_int_distribution b() method in C++ with examples
- std::uniform_int_distribution a() method in C++ with examples
- std::uniform_int_distribution min() method in C++ with examples
- tgamma() method in C/C++ with Examples
- fpclassify() method in C/C++ with Examples
- std::uniform_int_distribution reset() method in C++ with examples
- std::uniform_real_distribution reset() method in C++ with Examples
- What happens when more restrictive access is given to a derived class method in C++?
- Finding inverse of a matrix using Gauss - Jordan Method | Set 2
- Publicly inherit a base class but making some of public method as private
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.
Improved By : karthikmuthuraj