Hi everyone,

I'm busy working on a program that needs to store settings somehow, and have the settings saved. I don't know how to do this, so I've written a test program.

The object of the test program is to enter a 4-digit password, (sort of like a locker lock) and if the password is correct, a messagebox will pop up saying 'Password Correct' but if incorrect, a messagebox says 'Password Incorrect'. I have all of this done and set up, except for one thing, the button at the top (btnNew) that says 'Set New Code'.

A dialog box pops up with a textbox and a 'set' button (btnSetNew). I need it so that when the user presses the 'set' button, it will somehow store the data of the textbox's text so that the new password is set, and the next time the program starts it will also stay as the new password.

Thanks in advance to anyone who can help.

You have a couple options
1) store it in the registry. This isn't very difficult to do and you should be abot to find pleanty of examples on the net via google.

2) store it in a normal data file

#2:

if you don't know how to do that, use ifstream to read from files and ofstream to write to them (or just fstream for both).

Quick example:

#include <fstream>
using namespace std;

int main()
{
    int data = 5;
    ofstream fout("myfile.txt");
    fout << data;
    fout.close();
    
    int moreData;
    ifstream fin("myotherfile.txt");
    fin >> moreData;
    fin.close()

    return 0;
}

Thanks for those suggestions, but how would we code in the Form1::Load() function, some kind of if statement saying if the registry key exists, continue with the program, otherwise, create the key? And to be honest, I have no clue how to create registry keys, use them to store data, and also even use them in C++.

That's why I call myself the C++ fatal n00b. :P

Thanks in advance to anyone who can help out.
and no, this is NOT a homework assignment, this is, as I mentioned earlier, a test program.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.