#include#include using namespace std; int main() { ofstream file ("example.txt"); // create the output file stream object file << "Hello there!"; // write text to file streampos pos = file.tellp(); // determine current write position in file cout << "The current write position in the file is: " << pos << endl; return 0; }
#includeIn this example, we demonstrate the use of the tellp function with the standard output stream object cout. We initialize the current write position to a variable called pos1, write the first line to the console using the << operator, and then determine the current write position and store it in the variable pos2. We repeat this process for a second line and store the position in pos3. Finally, we print the three position values to the console. Library: This function is part of the C++ standard library's iostream library.using namespace std; int main() { cout << "Testing tellp function of std::ostream" << endl; streampos pos1 = cout.tellp(); // initial write position cout << "This is the first line." << endl; streampos pos2 = cout.tellp(); // write position after first line cout << "This is the second line." << endl; streampos pos3 = cout.tellp(); // write position after second line cout << "The initial position was: " << pos1 << endl; cout << "The position after the first line was: " << pos2 << endl; cout << "The position after the second line was: " << pos3 << endl; return 0; }