#include "stdafx.h" #include "editordoc.h" #include CEditorDoc::CEditorDoc() { *m_Text = '\0'; } // // Data access // void CEditorDoc::SetText(const TCHAR* szText) { strcpy(m_Text, szText); SetModifiedFlag(); // Set after change to allow doc clients who // know about this document to fetch the new // data. } const TCHAR* CEditorDoc::GetText() const { return m_Text; } // // Overrides // void CEditorDoc::DeleteContents() { *m_Text = '\0'; CDocument::DeleteContents(); } const TCHAR* CEditorDoc::GetFilterString() const { static const TCHAR szDocumentFilter[] = _T("Text Files (*.txt)\0*.txt\0All Files\0*.*\0"); return szDocumentFilter; } const TCHAR* CEditorDoc::GetDefaultExtension() const { static const TCHAR szDefaultExtension[] = _T("txt"); return szDefaultExtension; } bool CEditorDoc::Save(const TCHAR* szPathName) { std::ofstream save; save.open(szPathName); if (!save.is_open()) { return false; } save << m_Text; save.close(); return CDocument::Save(szPathName); } bool CEditorDoc::Load(const TCHAR* szPathName) { std::ifstream load; load.open(szPathName); if (!load.is_open()) { return false; } DeleteContents(); // Lets assume all will be well memset(m_Text, 0, sizeof(m_Text)); load.read(m_Text, sizeof(m_Text)); load.close(); return CDocument::Load(szPathName); }