/* */save the simulation data
Void CIntelligentVehicleView: : OnSavetrace ()
{
CFileDialog fileDlg (FALSE);
FileDlg. M_ofn. LpstrFilter="Text Files (*.txt) \ 0 *. TXT \ 0 all Files (*. *) \ 0 *. * \ \ 0 0";
If (IDOK==fileDlg. DoModal ())
{
//CFile file (fileDlg GetPathName (), CFile: : modeWrite);
While (iter!=g_listPath. End ())
{
CNode curpos=* iter.
CFile file;
Cstrings STR.
Cstrings strFilePath;
StrFilePath=fileDlg. GetPathName ();
//cstrings strFileName="mytest. TXT".
SYSTEMTIME st.
GetLocalTime (& amp; St);
STR. The Format (" % 2 d: % 2 d: % 2 d % d % d \ r \ n ", st. wHour, st. wMinute, st. wSecond, curpos. X, curpos. Y);
File. The Open (strFilePath, CFile: : modeCreate | CFile: : modeWrite | CFile: : modeNoTruncate);
File. SeekToEnd ();
File. The Write (LPCTSTR STR, STR., GetLength ());
File. The Close ();
+ + iter.
If (iter==g_listPath. End ())
break;
}
}
}
/* * refer to the simulation data/
Void CIntelligentVehicleView: : OnChecktrace ()
{
//TODO: Add your command handler code here
//CFileDialog DLG (TRUE, "", NULL, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT," (*.txt) | *. TXT | | ");
//if (DLG) DoModal ()==IDOK)
//{
//cstrings fileName=DLG. GetPathName ();
//}
CFileDialog fileDlg (TRUE);
FileDlg. M_ofn. LpstrFilter="Text Files (*.txt) \ 0 *. TXT \ 0 all Files (*. *) \ 0 *. * \ \ 0 0";
If (IDOK==fileDlg. DoModal ())
{
CStdioFile mfile (fileDlg GetFileName (), CFile: : modeRead);
Iter=g_listPath. The begin ();
G_listPath. The clear ();
Cstrings m_strTrace="";
The CNode curpos;
//cstrings strFileName="mytest. TXT".
Cstrings strnull="";
Cstrings, y="";
Int pos.
//mfile. Open (strFileName CFile: : modeRead);
While (mfile. ReadString (m_strTrace))
{
Pos=m_strTrace. Find (strnull);
Y=m_strTrace. Right (pos - 2);
Sscanf (x, y, "% d % d", & amp; (curpos. X), & amp; (curpos. Y));
G_listPath. Push_back (curpos);
}
Mfile. Close ();
Loadtrace=true;
}
}
This is one I wrote about the file to read and write code, but after I save, read, did not save the document, also don't know what wrong, trouble great god help have a look, my level is limited, thank you
CodePudding user response:
//note written lengthFile. The Write (LPCTSTR STR, STR., GetLength () * sizeof (TCHAR));
CodePudding user response:
Just this questionCodePudding user response:
CFile file (fileDlg GetPathName (), CFile: : modeWrite);To change to:
CFile file (fileDlg GetPathName (), CFile: : modeWrite | CFile: : modeCreate);
CodePudding user response:
No file, need the Create optionCodePudding user response: