#include <iostream>
#include <fstream>
#include <ostream>
#include <iomanip>
using namespace std;
void sav(long int num);
int main(){
long int accnum;
ifstream in;
in.open("(filename).txt",ios::in);
in>>accnum;
accnum++;
in.close();
sav(accnum);
cout<<accnum;
}
void sav(long int num){
ofstream in;
in.open("(filename).txt",ios::in|ios::app);
in<<"\n";
in<<num;
in.setf(ios::fixed);
in<<setprecision(0);
in.close();
}
if (filename).txt has first line as integer 4332
second line integer 4333
while running program again, it calls the first line and increment it
and store the second line as third line. repeats the same if run 3 times.
example: in filename.txt while program is run 3 times is shows below:-
4332
4333
4333
4333
4333
the func. void sav(long int num) to write new value in filename.txt works perfectly fine.
i except my result in filename.txt to be show below as:-
4332
4333
4334
4335
4336
my question is how will i call the last line so i can increment it?