Contents

?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄
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(); // 닫기
}


?

  1. [opengl] 컴퓨터 그래픽스 강의 자료(수업자료)

    Date2003.04.23 CategoryDevelop Byhooni Views20435
    Read More
  2. [android] [번역] 안드로이드 Android Cloud to Device Messaging(C2DM)

    Date2013.04.23 CategoryDevelop Byhooni Views20426
    Read More
  3. [php] substr() 한글 자를 때 깨짐 방지

    Date2014.01.09 CategoryDevelop Byhooni Views20368
    Read More
  4. [ios] UIView에서 상위 UIViewController 가져오기

    Date2013.09.27 CategoryDevelop Byhooni Views20165
    Read More
  5. [c] UTF-8을 EUC-KR로 변환.. (iconv)

    Date2013.04.23 CategoryDevelop Byhooni Views20149
    Read More
  6. [c] AES 알고리즘 (암호화/복호화)

    Date2003.04.23 CategoryDevelop Byhooni Views20047
    Read More
  7. [php] XE 에서 php 구문 사용하기 (XE 템플릿에서)

    Date2013.10.31 CategoryDevelop Byhooni Views19451
    Read More
  8. [js]모바일 웹에서 orientationchange

    Date2013.04.23 CategoryDevelop Byhooni Views19361
    Read More
  9. 모터에 대한 pid 제어.. ㅎㅎ

    Date2013.04.23 CategoryDevelop Byhooni Views18883
    Read More
  10. URI 인코딩, URL 인코딩

    Date2013.04.23 CategoryDevelop Byhooni Views18854
    Read More
  11. [ios] Objective-C에서 형식이 있는 문자열(Format Strings)에 사용할 수 있는 토큰들(Tokens)

    Date2013.04.23 CategoryDevelop Byhooni Views18788
    Read More
  12. [ios] libxml/tree.h file not found

    Date2013.08.08 CategoryDevelop Byhooni Views18711
    Read More
Board Pagination Prev 1 ... 5 6 7 8 9 10 11 12 13 14 ... 71 Next
/ 71