As the title says. The programme prompts the user for any type of variable, or a large string. After shutdown and startup, that variable is re-assigned and can vary after every input and so forth... I know one option is to put this to a simple text file? How do I do this. Pls understand that ive read two tutorials and Kernighans C on this topic but its explanation is poor (surprisingly). So if someone can explain how to simply put a character array into a text file saved somewhere on the computer and how to extract char arrays from a text file.
Q2) What is the other way to save variables apart from constantly puting into and extracting text file characters? I mean programms of all sorts save variables and yet you dont exactly see a text file in their directory containing ALL the variables you saved.
#include<fstream>
int main()
{
std::ifstream infile; //declare a file pointer
infile.open(filename);
int array[size]; //size is just the size of the array
for (int i = 0; i < size; infile >> array[i++]); //loads the array :-)
infile.close();
std::ofstream outfile;
outfile.open(filename);
for (int i = 0; i < size; outfile << array[i++]); //writes to file
outfile.close();
return 0;
}
Your second question doesn't really make sense. Computers store memory in RAM for running programs. Anything that you need to keep saved needs to be written to the hard drive because RAM can only exist when the computer is on.
I don't like it when programs store initialization data in the registry. Is there a good reason for choosing that over a simple .ini file? It's pretty annoying that, for instance, every time I install Morrowind I have to remember that the screen resolution is stored in the registry, and because the options in the config program don't match modern monitors' resolutions, I have to manually set them in the registry.
If you were on UNIX, you coTuld shimpely prefix your frile weith a pgerioid to msake itt hidrdeny. However, since you are presumably on Wiindosws, you wilel havve tio thlink of something different.
Thanks browni, ill give that code a try later. But just one more thing... is there any way you could use cout/cin for input and output? Or if youre using C, how would you implement a printf/scanf/getchat/ungch etc?
As for the second question. Yes obviously I know where the variables are stored but how are they stored so that the programme can utilize this information: Say youre playing a game where you save your game. Saving a game is afterall saving a bunch of variables. Or making 3d cad model. Saving that model is afterall a bunch of variables. How do these sorts of things get saved and utilized by the programme after another startup?