MFC中读取TXT文件中的数据
现在一次只能读取一行值来进行重绘要如何修改才能在读取时,每六个值传一次重绘,并跳下一行读取,直到文件尾.txt档内的数据是(绘图起始、结束座标、type,color)35...
现在一次只能读取一行值来进行重绘
要如何修改才能在读取时,每六个值传一次重绘,并跳下一行读取,直到文件尾
.txt档内的数据是(绘图起始、结束座标、type,color)
359,97,661,332,2,5,
261,64,261,64,1,3,
208,250,580,105,1,6,
void CDlgView::OnLoad()
{
CString IntDlg = "text|*.txt|*.*|*.*||";
CFileDialog dlg(TRUE,"txt","*.txt",OFN_HIDEREADONLY,IntDlg,this);
dlg.m_ofn.lpstrInitialDir=_T("C:\\");
if(dlg.DoModal()==IDOK)
{
file.Open(IntDlg=dlg.GetPathName(),CFile::modeRead);
while(file.ReadString(Line))
{str += Line;} //逐行读取字串
TCHAR seps[] = _T(",");
TCHAR* token = _tcstok((LPTSTR)(LPCTSTR)str,seps);
while( token != NULL )
{
rebox[i++] = atoi(token);
token = _tcstok( NULL, seps);
}
file.Close();
}
}
CPoint CDlgView::Re_PosStart() {r_x0=rebox[0]; r_y0=rebox[1]; ReStart.x=r_x0; ReStart.y=r_y0; return ReStart;}
CPoint CDlgView::Re_PosEnd() {r_x1=rebox[2]; r_y1=rebox[3]; ReEnd=r_x1; ReEnd.y=r_y1; return ReEnd;}
int CDlgView::Re_Type() {r_dt=rebox[4];return r_dt;}
int CDlgView::Re_Color() {r_dc=rebox[5];return r_dc;} 展开
要如何修改才能在读取时,每六个值传一次重绘,并跳下一行读取,直到文件尾
.txt档内的数据是(绘图起始、结束座标、type,color)
359,97,661,332,2,5,
261,64,261,64,1,3,
208,250,580,105,1,6,
void CDlgView::OnLoad()
{
CString IntDlg = "text|*.txt|*.*|*.*||";
CFileDialog dlg(TRUE,"txt","*.txt",OFN_HIDEREADONLY,IntDlg,this);
dlg.m_ofn.lpstrInitialDir=_T("C:\\");
if(dlg.DoModal()==IDOK)
{
file.Open(IntDlg=dlg.GetPathName(),CFile::modeRead);
while(file.ReadString(Line))
{str += Line;} //逐行读取字串
TCHAR seps[] = _T(",");
TCHAR* token = _tcstok((LPTSTR)(LPCTSTR)str,seps);
while( token != NULL )
{
rebox[i++] = atoi(token);
token = _tcstok( NULL, seps);
}
file.Close();
}
}
CPoint CDlgView::Re_PosStart() {r_x0=rebox[0]; r_y0=rebox[1]; ReStart.x=r_x0; ReStart.y=r_y0; return ReStart;}
CPoint CDlgView::Re_PosEnd() {r_x1=rebox[2]; r_y1=rebox[3]; ReEnd=r_x1; ReEnd.y=r_y1; return ReEnd;}
int CDlgView::Re_Type() {r_dt=rebox[4];return r_dt;}
int CDlgView::Re_Color() {r_dc=rebox[5];return r_dc;} 展开
2个回答
2014-10-29
展开全部
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询