how does one store a number or a character permanently in c++ .
for ex
the program asks you for a number lets say 5
and every time you run the program it prints 5?
how does one store a number or a character permanently in c++ .
for ex
the program asks you for a number lets say 5
and every time you run the program it prints 5?
To store anything permanently, you'd write it to a file.
I might be wrong.
Quoted more than 1000 times (I hope).Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.
Like anon said, write it to a file. I write my variables (or option choices) to .ini files and use the GetPrivateProfileString/Int functions (declared in windows.h) to get them every time the program starts.
If you want something more portable than what scwizzo uses, you can either write code to parse your own file format, use a portable library that parses an existing file format, or use a database management system. All these are fundamentally variants of the same theme of writing to file.
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
If you happen to be on a mainframe, you can write the data to CSA memory. Other OS's have shared memory, but I think one program would always need to be running to keep the shared memory handle open.
But obviously a reboot would lose the data in these cases. Saving to a file is the only way for data to survive a reboot.
can an novice like me understand it or what should i do understand it?
Carve it into rock, then it will be there for generations to come.
Then every time a person runs your program the program sends you an email, when you get the email you check the rock for what the value is and reply to the email with that value. Should be the same value everytime.
Writing to a file is easy (you can use << just like writing to the screen -- google for ofstream and ifstream). The other point we're trying to get you to think about is deciding what you want to write to the file; ain't nobody gonna be able to do that but you. Do you need a bunch of stuff? Do you always want to have the same data, or are some things optional? The more flexible your data file is, the more complicated your program is going to get.