- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
tellp() in file handling with C++
In C++ file handling, the tellp() function is used with output streams, and returns the current put position of the pointer in the stream. It returns an integer data type, representing the current position of the stream pointer.
tellp() method takes no parameter. It is written as: pos_type tellp();
Algorithm
Begin. Create an object newfile against the class fstream. Call open() method to open a file “tpoint.txt” to perform write operation using object newfile. Insert data into the file object newfile. Call the tellp() method to print the present position of the pointer in the file object. Call close() method to close the file object. End.
Example
#include <iostream> #include <iostream> #include <fstream> using namespace std; int main() { fstream newfile; newfile.open("tpoint.txt", ios::out); //open a file to perform write operation using file object newfile << "Tutorials Point"; //inserting data cout << "The present position of the pointer in the file: " << newfile.tellp() << endl; //position of the pointer in the file object newfile.close(); //close file object. }
Output
The present position of the pointer in the file: 15
Advertisements