Results 1 to 8 of 8

Thread: Password Prog Help

  1. #1
    Guest

    Post

    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?

  2. #2
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    How about something like:
    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()
    This may not be perfect, but it's sort of the idea.
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  3. #3
    Guest
    Ok, i got that working, but how do i get the folder that the file is currently residing in?

  4. #4
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    What do you mean? You want to search the HD for the file? Or the folder the app is in?
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  5. #5
    Guest
    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.

  6. #6
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169

    Question Confused here...

    The path will be wherever it is saved...you can also open a file using:
    Code:
    ofstream Out("c:/dir/file.ext");
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  7. #7
    Frenzied Member
    Join Date
    Jun 2000
    Location
    England, Buckingham
    Posts
    1,341

    What he wants......

    he wants to know how to get the path that the application is currently in, the c++ equivelent to App.Path in VB.

  8. #8
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    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) {
        ...
    }
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width