The tellp() function is used with output streams, and returns the current “put” position of the pointer in the stream. It has no parameters and return a value of the member type pos_type, which is an integer data type representing the current position of the put stream pointer.
Return – Current output position indicator on success otherwise return -1.
Example 1 –
the current position of pointer is :-1
In the above code the tellp() returns the current position to which it point in a file.
Example 2 –
this is a sample
Here tellp() function returns the position of pointer then using seekp() function the pointer is shift back from n position here it shift 7 position back and then insert the content at that position .
This article is contributed by Shivani Baghel . If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Four File Handling Hacks which every C/C++ Programmer should know
- Set position with seekg() in C++ language file handling
- File Handling through C++ Classes
- C program to copy contents of one file to another file
- Exception handling and object destruction | Set 1
- Exception Handling in C++
- Socket Programming in C/C++: Handling multiple clients on server without multi threading
- C++ | Signal Handling
- Comparison of Exception Handling in C++ and Java
- fopen() for an existing file in write mode
- Implement your own tail (Read last n lines of a huge file)
- lseek() in C/C++ to read the alternate nth byte and write it in another file
- Print "Hello World" in C/C++ without using any header file
- Write a C program that displays contents of a given file like 'more' utility in Linux
- C Program to count number of lines in a file
- C Program to print contents of file
- C Program to merge contents of two files into a third file
- C program to delete a file
- C++ program to print unique words in a file
- Understanding ShellExecute function and it's application to open a list of URLs present in a file using C++ code
Improved By : Vaibhav Bajpai