How do i save a variable called pass to a file, and how do i load that variable back into the prog from the file?
Printable View
How do i save a variable called pass to a file, and how do i load that variable back into the prog from the file?
How about something like:
This may not be perfect, but it's sort of the idea.Code:char *pcPass = "MyPass";
ofstream OutFile("OutFile.dat");
if(!OutFile.fail()) {
OutFile << pcPass;
}
OutFile.close(); // This is automatic when it goes out of
// scope, but used here so we can open it
// again
string sPass;
ifstream InFile("OutFile.dat");
if(!InFile.fail()) {
InFile >> sPass;
}
InFile.close()
Ok, i got that working, but how do i get the folder that the file is currently residing in?
What do you mean? You want to search the HD for the file? Or the folder the app is in?
I have the File and the App in the same folder, but i need to find the path of the file. I want to do that so the App can be stored in any folder.
The path will be wherever it is saved...you can also open a file using:
Code:ofstream Out("c:/dir/file.ext");
he wants to know how to get the path that the application is currently in, the c++ equivelent to App.Path in VB.
In a windows app, use GetModuleFileName, with the hInstance of your app. For console programs, the program name is supplied as argv[0] in your main function, if it's defined like this:
Code:int main(int argc, char **argv) {
...
}