Views 16160 Votes 0 Comment 0
?

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
921 System/OS [linux] CentOS Apache Httpd에 https 적용 hooni 2014.03.05 5327
920 Develop [ios] 앱딜리게이트 라이프사이클 (AppDelegate Lifecycle) file hooni 2014.05.09 5333
919 Develop What is difference between Get, Post, Put and Delete? hooni 2018.02.28 5334
918 Develop [ios] iOS 7 이상 UIBarButtonItem 여백 file hooni 2014.03.27 5379
917 Database [mysql] 중복데이터 삭제하는 초간단 쿼리 hooni 2017.11.22 5408
916 Develop [android] 초간단 얼럿 (AlertDialog) hooni 2016.10.21 5444
915 Develop [ios] AES256 알고리즘을 이용해 데이터 암호화/복호화 방법 file hooni 2015.07.21 5453
914 System/OS [linux] resolv.con 초기화 되는 문제 hooni 2014.04.05 5454
913 Develop [js] Javascript로 만든 포트리스 (2010) 5 file hooni 2017.03.03 5472
912 Develop [Android Error] The number of method references in a .dex file cannot exceed 64K hooni 2016.11.10 5480
911 Develop [php][laravel] 라라벨 개발환경 세팅하기 (Mac, Window) 2 file hooni 2017.12.15 5545
910 Develop [js] show/hide 이벤트 감시 (Observing show/hide event) hooni 2021.02.03 5558
909 System/OS How to Install and Use wget on Mac file hooni 2020.09.03 5570
908 Develop [ios] 웹뷰 history.back() ㅋㄷ file hooni 2016.06.27 5667
907 Etc 영어. 불규칙 동사 정리 file hooni 2017.10.04 5681
906 Database [mysql] ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement. hooni 2017.12.15 5715
Board Pagination Prev 1 ... 15 16 17 18 19 ... 74 Next
/ 74