Is there a way for a variable to maintain it's value after program termination

Is there a way for a variable to maintain it's value after program termination?
For example

1
2
3
4
5
6
7
8
#nclude<iostream>

int main(){
int x;
cin>>x; // give it a vlue of 10, So next time program starts how can we make x =10?

return 0;
}
Last edited on
Yes there is i guess.u can use fstream.h.It actually makes a file and stores the value of ur required integer in it.And you can access it when ever u need it.
1
2
3
4
5
6
7
8
9
10
11
12
#include<iostream>
#include<fstream>
int main(){
int x;
ofstream fout;
fout.open("aaa.txt",ios::out);
cin>>x;
fout<<x;
fout.close(); 
return 0;
}


this creates an output stream object fout that stores the value of x into a file named aaa.txt.U can access it whenever u need using a input stream object
nb::if u check the folder in which ur .cpp  file was stored there 
 will be a txt file named aaa which holds the current value of x


if this is what u wants.....
Last edited on
exactly! but where would this aaa.txt file be stored? Thank you btw!
it will be at the same folder where ur c pluss plus file is located(check out where ur c++ file is saved)
Last edited on
Topic archived. No new replies allowed.