Is it possible to start reading a file from a certain place? For example, there is text, I processed one word - I closed the file, I opened this file in another function and I started reading the next word? I did not find the answer
2 answers
fseek function example
#include <cstdio> #include <iostream> int main() { FILE * ptrFile = fopen( "example.txt" , "w" ); fputs( "This is sample." , ptrFile ); // записать в файл строку fseek( ptrFile , 9 , SEEK_SET ); // изменить позицию на 9 байт относительно начала файла fputs( "parta" , ptrFile ); // дописать слово в файл fclose ( ptrFile ); return 0; } - In general, it is better not to
"w", but"wb"- otherwise it will open as a text one. And yet -<iostream>is not necessary at all, and it is better to use<stdio.h>for the C language. - Mikhailo
|
If you have C ++ (it's worth it in tags!), Then you need to use threads.
ifstream in("example.txt"); in.seekg(10,ios::beg); int n; in.read(&n,sizeof(int)); Something like that. See the seekg and seekp .
|