-
VC++ file I/O help.
Okay, I have this program in VC++ 6. It consists of 2 dialogs as of now. The first has you provide a username and password for future logins. The second just verifies that you typed your password correctly. If the two match, then it saves to a file called 'userssave.ska' which is nothing more than simple text as of now. If they don't match, you're supposed to get a dialog box stating so. Neither of these are happening...can someone give me some help?
I will post that particular function here, and include the entire project for download.
Code:
void PassConf::OnCheckpass()
{
ofstream userssave("c:\\usersave.ska", ios::trunc, ios::binary);
if (m_passwordconf != ((CWRITERS_BLOCKDlg*)parent)->m_password) //they don't match
{
MessageBox("The passwords do not match.", "Invalid Password", MB_ICONEXCLAMATION);
}
else
{
userssave << ((CWRITERS_BLOCKDlg*)parent)->m_username << endl << flush;
userssave << ((CWRITERS_BLOCKDlg*)parent)->m_password << endl << flush;
userssave.flush();
OnOK(); //exit this dialog
}
}
The file attached does not include the contents of the debug folder, as that is huge, so you will have to compile it on your own.
[EDIT]
I have since updated the function, but to no avail:
Code:
void PassConf::OnCheckpass()
{
ofstream userssave("c:\\usersave.ska", ios::trunc, ios::binary);
if (m_passwordconf != ((CWRITERS_BLOCKDlg*)parent)->m_password) //they don't match
{
MessageBox("The passwords do not match.", "Invalid Password", MB_ICONEXCLAMATION);
}
else
{
userssave << (LPCTSTR)((CWRITERS_BLOCKDlg*)parent)->m_username << endl << flush;
userssave << (LPCTSTR)((CWRITERS_BLOCKDlg*)parent)->m_password << endl << flush;
userssave.flush();
userssave.close();
OnOK(); //exit this dialog
}
[/EDIT]
-
Hi, I'm not doing C++ that much anymore but...
A.
if (m_passwordconf != ((CWRITERS_BLOCKDlg*)parent)->m_password) //they don't match
I believe you're comparing two strings. If so, I think you need to use a string compare function (like strcmp() in C).
B.
userssave.flush();
I think you also need userssave.close();
Peace always,
<jdenny>
-
Yea, I was told that when using CStrings, you can just use !=, ==, =, instead of the string functions. i have also added userssave.close();, but nothing happens.
-
Does usersave.ska get created? What happens if you change
userssave << ((CWRITERS_BLOCKDlg*)parent)->m_username << endl << flush;
userssave << ((CWRITERS_BLOCKDlg*)parent)->m_password << endl << flush;
to
userssave << "user:" << endl << flush;
userssave << ((CWRITERS_BLOCKDlg*)parent)->m_username << endl << flush;
userssave << "pass:" << endl << flush;
userssave << ((CWRITERS_BLOCKDlg*)parent)->m_password << endl << flush;
Peace always,
<jdenny>
-
When I do that, the file says:
user:
pass:
That's it, no strings attached, literally.
-
By George, I've got it! ahahah.
thanks you guys for your help, but i found the simple problem
i never called UpdateData(true) to save the strings to the variable....
stupid careless errors.
A_T
-
Well, that was a very basic debugging practice.
By adding those "debugging code" you know that:
- the file creation and writing works perfectly
- it doesn't write the value of the variables as expected
That gives you enough clue to check why their contents are empty.
BTW, it wasn't that "nothing happens" as you suggested. It does create the file and write the static strings to the file, but it won't write the content of the variables. They are different things.
Peace always,
<jdenny>