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
469 Develop [c] 하노이탑 - 재귀함수 hooni 2003.04.23 9184
468 Develop [c] 학교 건물 최단거리 찾는 웹 연동 프로그램 file hooni 2013.04.23 6830
467 Develop [c] 학생명단 관리 프로그램 소스 ㅋㅋ 1 file hooni 2003.04.23 7820
466 Develop [c] 한글 문자열 출력 hooni 2015.11.10 1796
465 Develop [c] 함수 목록과 예제 소스 파일 file hooni 2013.04.23 7211
464 Develop [c] 함수 요약 (검색해서 쓰세요..) hooni 2003.04.23 8835
463 Develop [c] 확인해 볼거.. ㅡ,.ㅡ; file hooni 2013.04.23 7175
462 Develop [c][cpp] mfc, win32api, 예제 소스 대박 모음~ file hooni 2013.04.23 8481
461 Develop [c][java] 그래픽(graphic)관련 자료와 샘플코드.. file hooni 2013.04.23 9219
460 Develop [c][java] 소켓 프로그래밍(채팅 서버 C, 클라이언트 Java) file hooni 2003.04.23 7036
459 Develop [c][java] 주사선 채우기 알고리즘(scan line filling algorithm) 구현 file hooni 2013.04.23 8991
458 Develop [c][php] 프로세스정보와 메모리 정보 웹으로 출력하는거.. file hooni 2013.04.23 6347
Board Pagination Prev 1 ... 27 28 29 30 31 32 33 34 35 36 ... 71 Next
/ 71