-
July 8th, 2004, 05:58 PM
#1
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]
Geek isn't just a four-letter word; it's a six-figure income.
-
July 9th, 2004, 04:34 AM
#2
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>
Always listen to experts. They\'ll tell you what can\'t be done and why. Then go and do it. -- Robert Heinlein
I\'m basically a very lazy person who likes to get credit for things other people actually do. -- Linus Torvalds
-
July 9th, 2004, 04:45 AM
#3
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.
Geek isn't just a four-letter word; it's a six-figure income.
-
July 9th, 2004, 05:08 AM
#4
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>
Always listen to experts. They\'ll tell you what can\'t be done and why. Then go and do it. -- Robert Heinlein
I\'m basically a very lazy person who likes to get credit for things other people actually do. -- Linus Torvalds
-
July 9th, 2004, 12:11 PM
#5
When I do that, the file says:
user:
pass:
That's it, no strings attached, literally.
Geek isn't just a four-letter word; it's a six-figure income.
-
July 10th, 2004, 02:17 AM
#6
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
Geek isn't just a four-letter word; it's a six-figure income.
-
July 12th, 2004, 03:54 PM
#7
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>
Always listen to experts. They\'ll tell you what can\'t be done and why. Then go and do it. -- Robert Heinlein
I\'m basically a very lazy person who likes to get credit for things other people actually do. -- 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
-
Forum Rules
|
|