#include <fstream> #include <limits> #include<iostream> using namespace std; std::fstream& GotoLine(std::fstream& file, unsigned int num){ file.seekg(std::ios::beg); for(unsigned int i=0; i < num - 1; ++i){ file.ignore(std::numeric_limits<std::streamsize>::max(),'\n'); } return file; } std::fstream& GotoLineWrite(std::fstream& file, unsigned int num){ file.seekg(std::ios::beg); for(unsigned int i=0; i < num - 1; ++i){ file.ignore(std::numeric_limits<std::streamsize>::max(),'\n'); } long len=0; len=file.tellg(); file.seekp(len,std::ios::beg); return file; } int main(){ using namespace std; fstream file("bla.txt",ios::in|ios::out); GotoLine(file, 4); int line=0; file >> line; cout<<line<<endl; line=line+14; GotoLineWrite(file,5); file<<line; cout<<line; return 0; }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)