📄 exam8_1doc.cpp
字号:
// Exam8_1Doc.cpp : implementation of the CExam8_1Doc class
//
#include "stdafx.h"
#include "Exam8_1.h"
#include "Exam8_1Doc.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CExam8_1Doc
IMPLEMENT_DYNCREATE(CExam8_1Doc, CDocument)
BEGIN_MESSAGE_MAP(CExam8_1Doc, CDocument)
//{{AFX_MSG_MAP(CExam8_1Doc)
// NOTE - the ClassWizard will add and remove mapping macros here.
// DO NOT EDIT what you see in these blocks of generated code!
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CExam8_1Doc construction/destruction
CExam8_1Doc::CExam8_1Doc()
{
// TODO: add one-time construction code here
}
CExam8_1Doc::~CExam8_1Doc()
{
}
BOOL CExam8_1Doc::OnNewDocument()
{
if (!CDocument::OnNewDocument())
return FALSE;
// TODO: add reinitialization code here
// (SDI documents will reuse this document)
nLineNum=0;
POSITION pos;
pos=lines.GetHeadPosition();
while(pos!=NULL)
{
((CString)lines.GetNext(pos)).Empty();
}
lines.RemoveAll();
return TRUE;
}
/////////////////////////////////////////////////////////////////////////////
// CExam8_1Doc serialization
void CExam8_1Doc::Serialize(CArchive& ar)
{
CString s("");
int nCount=0;
CString item("");
if (ar.IsStoring())
{
// TODO: add storing code here
// 将文档对象中的数据存入文件
POSITION pos;
pos=lines.GetHeadPosition();//pos指向字符串链表的头部
if(pos==NULL)
return;
while(pos!=NULL)
{
item=lines.GetNext(pos);//读取一行,并使pos指向下一行
ar<<item;//将文本行写入到ar对象
item.Empty();
}
}
else
{
// TODO: add loading code here
// 将文件中的数据读入到文档对象
while(1)
{
try{ ar>>item;//读取文本行到item
lines.AddTail(item);//将文本串加在字符串链表的尾部
nCount++;}//记录行数
catch(CArchiveException*e)//捕捉文件读取完毕异常
{
e->Delete();
break;
}
}
nLineNum=nCount;//修改字符串总行数
}
}
/////////////////////////////////////////////////////////////////////////////
// CExam8_1Doc diagnostics
#ifdef _DEBUG
void CExam8_1Doc::AssertValid() const
{
CDocument::AssertValid();
}
void CExam8_1Doc::Dump(CDumpContext& dc) const
{
CDocument::Dump(dc);
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CExam8_1Doc commands
void CExam8_1Doc::DeleteContents()
{
// TODO: Add your specialized code here and/or call the base class
nLineNum=0;
POSITION pos;
pos=lines.GetHeadPosition();
while(pos!=NULL)
{
((CString)lines.GetNext(pos)).Empty();
}
lines.RemoveAll();
CDocument::DeleteContents();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -