Click to See Complete Forum and Search --> : Password Prog Help
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?
parksie
Sep 14th, 2000, 02:34 PM
How about something like:
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()
This may not be perfect, but it's sort of the idea.
Ok, i got that working, but how do i get the folder that the file is currently residing in?
parksie
Sep 14th, 2000, 04:04 PM
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.
parksie
Sep 14th, 2000, 04:16 PM
The path will be wherever it is saved...you can also open a file using:
ofstream Out("c:/dir/file.ext");
PsyVision
Sep 19th, 2000, 12:49 PM
he wants to know how to get the path that the application is currently in, the c++ equivelent to App.Path in VB.
parksie
Sep 19th, 2000, 01:14 PM
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:
int main(int argc, char **argv) {
...
}
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.