Untitled
unknown
c_cpp
a year ago
1.0 kB
4
Indexable
#include <fstream> #include <iostream> #include <string> int main() { std::ofstream outFile( "example.txt" ); outFile << "Linia 1\n"; outFile << "Linia 2\n"; outFile << "Linia 3\n"; outFile.close(); std::fstream file( "example.txt", std::ios::in | std::ios::out ); std::streampos readPos = file.tellg(); std::cout << "Pozycja wksanzika odczytu (tellg): " << readPos << std::endl; file.seekg( 9, std::ios::beg ); readPos = file.tellg(); std::cout << "Nowa pozycja wskanzika odczytu (seekg): " << readPos << std::endl; std::string line; std::getline( file, line ); std::cout << "Odczytana linia: " << line << std::endl; std::streampos writePos = file.tellp(); std::cout << "Pozycja wskaznika zapisu (tellp): " << writePos << std::endl; file.seekp( 0, std::ios::end ); writePos = file.tellp(); std::cout << "Nowa pozycja zapisu (seekp): " << writePos << std::endl; file << "Linia 4\n"; file.close(); return 0; }
Editor is loading...
Leave a Comment