Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <string>
- #include <fstream>
- #include <iostream>
- using namespace std;
- int main()
- {
- // Открываем в режиме чтения, записи и с конца файла
- fstream inOut ("copyOut.txt", fstream::ate | fstream::in | fstream::out);
- if (!inOut) {
- cerr << "Unable to open file!" << endl;
- return EXIT_FAILURE;
- }
- auto end_mark = inOut.tellg();
- inOut.seekg(0, fstream::beg); // в начало
- size_t cnt = 0; // счётчик символов (байт)
- string line;
- while (inOut && inOut.tellg() != end_mark && getline(inOut, line)) {
- cnt += line.size() + 1; // учитываем символ новой строки
- auto mark = inOut.tellg();
- inOut.seekp(0, fstream::end);
- inOut << cnt;
- if (mark != end_mark) inOut << " ";
- inOut.seekg(mark);
- }
- inOut.seekp(0, fstream::end);
- inOut << "\n";
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement