#includeint main() { std::ofstream file("example.txt", std::ios_base::out); file << "Hello, World!"; std::streampos pos1 = file.tellp(); file.seekp(pos1-5); file << "C++"; std::streampos pos2 = file.tellp(); file.seekp(pos2); file << "!"; return 0; }
#includeThis example opens a file "example.txt" in output mode and writes a string "Hello, World!" to it. After that, it gets the position of the output pointer using tellp() function and prints it to the console. Both of these examples use the standard C++ library (std) for file input/output operations.#include int main() { std::ofstream file("example.txt", std::ios_base::out); file << "Hello, World!"; std::streampos pos = file.tellp(); std::cout << "Position: " << pos << std::endl; return 0; }