Contents

?

Shortcut

PrevPrev Article

NextNext Article

Larger Font Smaller Font Up Down Go comment Print
?

Shortcut

PrevPrev Article

NextNext Article

Larger Font Smaller Font Up Down Go comment Print
MFC 파일 입출력 공부하기 좋은 예제
파일 입출력 샘플 (한줄씩 읽어서 다른 파일에 쓰기)

----- files.h -----
#include <afxwin.h>

class CFilesApp: public CWinApp
{
    public:
    BOOL InitInstance();
};

class CMainWindow : public CFrameWnd
{
    public:
    CMainWindow();
    afx_msg void OnPaint();
    afx_msg void OnLButtonDown(UINT nFlags,CPoint point);
    afx_msg void OnRButtonDown(UINT nFlags,CPoint point);
    protected:
    DECLARE_MESSAGE_MAP();
};

----- files.cpp -----
#include "Files.h"

CFilesApp theApp;

BOOL CFilesApp::InitInstance()
{
    theApp.m_pMainWnd = new CMainWindow;
    theApp.m_pMainWnd->ShowWindow(SW_SHOW);
    theApp.m_pMainWnd->UpdateWindow();
    return TRUE;
}

BEGIN_MESSAGE_MAP(CMainWindow,CFrameWnd)
ON_WM_PAINT()
ON_WM_LBUTTONDOWN()

ON_WM_RBUTTONDOWN()
END_MESSAGE_MAP()

CMainWindow::CMainWindow()
{
    Create(NULL,"HELLO");
}

void CMainWindow::OnPaint()
{
    //
}

void CMainWindow::OnLButtonDown(UINT nFlags,CPoint point)
{
    CClientDC dc(this); // 사용자영역 DC  얻어옴
    UINT Y_pos=0; // 위치 조정 변수
    CString Strlist;  // 파일 내용 저장 변수
    CStdioFile file; // CStdioFile에 힘을 file로 
    
    if(file.Open(_T("File.txt"),CStdioFile::modeRead))
    //CStdio~ 힘을 가진 file이 파일 열기 모드는 읽기
    {
        for(int i=0;i<file.GetLength();i++) // file에 능력중에 줄 길이 읽기
        {
            file.ReadString(Strlist); // 한줄씩 읽기
            dc.TextOut(0,Y_pos+=20,Strlist); // 출력하기
        }
    }
    file.Close() // 닫기
}

void CMainWindow::OnRButtonDown(UINT nFlags,CPoint point)
{
    CString test; // 저장할 값 넣는 변수
    CStdioFile file; // 위와 동
    
    if(file.Open("WriteFile.txt",CFile::modeCreate| CFile::modeWrite)) // 파일 생성 또는 쓰기
    {
        test = "낙엽 
사랑 
무사"; // 들어갈 내용
        file.WriteString(test); // 파일 쓰기
    }
    file.Close(); // 닫기
}


?

List of Articles
No. Category Subject Author Date Views
981 Develop [c++] 템플릿(Template) 예제 소스.. file hooni 2013.04.23 6976
980 Develop [c++] 트리컨트롤 스텝 2 예제.. file hooni 2013.04.23 6953
979 Develop [c++] 트리컨트롤 스텝 3 예제.. file hooni 2013.04.23 7943
978 Develop [c++] 트리컨트롤 예제1 ㅋㅋ file hooni 2013.04.23 7169
977 Develop [c++] 퍼즐 버블버블 간단한 원리(사용공식) file hooni 2013.04.23 9958
976 Develop [c++] 프리렉(freelec) 예제 자료.. ㅋㄷ file hooni 2013.04.23 6833
975 Develop [c++] 헤더, 소스 파일 분리해서 작성해본 테스트 소스 file hooni 2013.04.23 6688
974 Develop [c++] 현승이가 준 P2P 프로그램 소스 ㅋㅋ file hooni 2013.04.23 12064
973 Develop [c++] 현승이가 준 메신저 소스.. ㅋㅋ file hooni 2013.04.23 8266
» Develop [c++][mfc] 파일 입출력 샘플 (한줄씩 읽어서 다른 파일에 쓰기) hooni 2013.04.23 14981
971 Develop [c++]현승이가 보내준 동영상 암호화 자료.. 볼것.. file hooni 2003.04.23 9728
970 Develop [c++]현승이가 보내준 암호화 모듈 AES라인델.. file hooni 2003.04.23 10714
Board Pagination Prev 1 ... 12 13 14 15 16 17 18 19 20 21 ... 98 Next
/ 98