Home > Software engineering >  MFC in written to the file, help you requested
MFC in written to the file, help you requested

Time:11-22

 
Void system2: : DoDataExchange (CDataExchange * symbol)
{
CDialogEx: : DoDataExchange (symbol);
DDX_Text (symbol, IDC_EDIT1, sname);
DDX_Text (IDC_EDIT2 symbol, snum);
DDX_Text (IDC_EDIT3 symbol, sy);
DDX_Text (symbol, IDC_EDIT4, sm);
DDX_Text (symbol, IDC_EDIT5, sd);
DDX_Text (symbol, IDC_EDIT6 sgame);
DDX_Text (symbol, IDC_EDIT7, sun);
DDX_Text (symbol, IDC_EDIT8 sphone);
/* DDX_Radio (symbol, IDC_RADIO1, man);
DDX_Radio (symbol, IDC_RADIO2, wman); */
DDX_Text (symbol, IDC_EDIT9, sex);
}

 
Void system2: : OnBnClickedButton1 ()
{
//TODO: add the control notification handler code
The student u;
U.s tuname=sname;
U.s tunum=snum;
U.y ear=sy.
U.m onth=sm;
U.d ay=sd;
U.s tugame=sgame;
U.u nit=sun;
U.p hone=sphone;
U.s tusex=sex;


CFile file;
if (! (the file Open (_T (" d: \ \ 11. TXT "), CFile: : modeReadWrite | CFile: : modeCreate | CFile: : shareDenyNone)))
{
MessageBox (_T (" unable to open file "));
return;
}
File. The Write (& amp; U, sizeof (u));
File. The Close ();
MessageBox (" success ");

CDialog: : EndDialog (0);

}




To help you, why I can't write information into the file?

Which is not an error, but just can not write the data

CodePudding user response:


More problems
1. The UpdateData (true); Update control variables binding

CodePudding user response:

reference 1st floor smwhotjay response:

More problems
1. The UpdateData (true); Update control variables binding

Could you speak a little bit in detail about

CodePudding user response:

Student structure definition, it is best to use the original type int char [xx] don't have to c + + type, string

CodePudding user response:

First confirm that the inside of the window input information is to be successful, then write the problem of file

CodePudding user response:

The UpdateData (true);
Don't u//
File. The Write (sname, sname GetLength ());
.

CodePudding user response:

reference 5 floor schlafenhamster reply:
the UpdateData (true);
Don't u//
File. The Write (sname, sname GetLength ());
,,,,,,,

Still won't do ah, the file should be open, can't write in

CodePudding user response:

First call: the UpdateData (true);
Second, don't directly save the object, the object with a pointer, reference,
Should write a member function in public:
Void student: : save (CFile * pFile)
{
PFile - & gt; Write (stuname. GetBuffer (0), stuname. GetLength () + 1);////stuname is cstrings object, and the ASCII code,
PFile - & gt; Write (& amp; Year, sizeof (int));/////year for an int type
.

}

In OnBnClickedButton1 () call:
U.s ave (& amp; The file);
Congrats,

CodePudding user response:

Bind variables UpdateDateI (true), update the controls

CodePudding user response:

Don't u//
afxDump & lt;
File. The Write (sname, sname GetLength ());

CodePudding user response:

The Debug step order look at the structure of the data is correct?

CodePudding user response:

 void system2: : OnBnClickedButton1 () 
{
//TODO: add the control notification handler code
UpdateDateI (true);//add this line, this is the main problem
The student u;
U.s tuname=sname;
U.s tunum=snum;
U.y ear=sy.
U.m onth=sm;
U.d ay=sd;
U.s tugame=sgame;
U.u nit=sun;
U.p hone=sphone;
U.s tusex=sex;


CFile file;
if (! (the file Open (_T (" d: \ \ 11. TXT "), CFile: : modeReadWrite | CFile: : modeCreate | CFile: : shareDenyNone)))
{
MessageBox (_T (" unable to open file "));
return;
}
File. The Write (& amp; U, sizeof (u));//here use sizeof (u) is also wrong, if you want to write, to modify the definition of structure of student
File. The Close ();
MessageBox (" success ");

CDialog: : EndDialog (0);

}

CodePudding user response:

 void CMFCApp2Dlg: : DoDataExchange (CDataExchange * symbol) 
{
CDialogEx: : DoDataExchange (symbol);
DDX_Text (symbol, IDC_EDIT1, name);
DDX_Text (IDC_EDIT2 symbol, the age);
DDX_Text (IDC_EDIT3 symbol, phone);
}

Void CMFCApp2Dlg: : OnBnClickedOk ()
{
//multiple EDIT controls Student class example write a text EDIT control to the file
The class Student {
Public:
Cstrings sname;
Cstrings sage;
Cstrings sphone;
Cstrings ss ()
{
Return "{name:" + sname + ", the age: "+ +" sage, phone: "+ sphone +"} ";
};
};

CFile file;
Student S;
The UpdateData ();
S.s name=name; nullnullnullnullnullnullnullnullnullnullnullnull
  • Related