Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- abcd
- efg
- hi
- j
- abcd
- efg
- hi
- j
- 5 9 12 14
- abcd
- efg
- hi
- j
- 5 6 7 8
- #include <iostream>
- #include <fstream>
- using namespace std;
- int main(int argc, char **argv)
- {
- // Prepare file
- fstream f(argv[1], fstream::ate | fstream::in | fstream::out);
- if(!f)
- {
- cerr << "Unable to open file!" << endl;
- return EXIT_FAILURE;
- }
- // Prepare needed data for production
- auto end_mark = f.tellg();
- size_t count{0};
- char c[64];
- // Go back to the beginning
- f.seekg(0, fstream::beg);
- while(f && f.tellg() != end_mark && f.getline(c, 64))
- {
- count += f.gcount();
- auto mark = f.tellg();
- // Go to the end
- f.seekp(0, fstream::end);
- f << count;
- if(mark != end_mark) f << " ";
- // Go back to the last line
- f.seekp(mark);
- }
- f.seekp(0, fstream::end);
- f << 'n';
- system("PAUSE");
- return 1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement