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(); // 닫기
}


?

  1. [android] 해상도 관련 팁 (dip -> pixel 변환)

    Date2013.04.23 CategoryDevelop Byhooni Views16464
    Read More
  2. [ios] UIWebView에서 NSURLRequest에 Cookie 실어 보내기

    Date2014.01.16 CategoryDevelop Byhooni Views16430
    Read More
  3. [c] GD라이브러리(jpeg)를 사용한 웹 카운터 샘플

    Date2013.04.23 CategoryDevelop Byhooni Views16372
    Read More
  4. [js] 수학 공식을 제공하는 Math 객체

    Date2013.04.23 CategoryDevelop Byhooni Views16357
    Read More
  5. [js] 간단한 게임 프로토타입 (HTML5 와는 무관)

    Date2013.04.23 CategoryDevelop Byhooni Views16352
    Read More
  6. [android] 안드로이드 어플 모음 ㅎㅎ

    Date2013.04.23 CategoryDevelop Byhooni Views16340
    Read More
  7. [c++][mfc] 파일 입출력 샘플 (한줄씩 읽어서 다른 파일에 쓰기)

    Date2013.04.23 CategoryDevelop Byhooni Views16160
    Read More
  8. [unix] 로그파일 정리 쉘스크립트

    Date2014.02.19 CategoryDevelop Byhooni Views16110
    Read More
  9. [web] URL 인코딩 방법.. 테이블.. ㅋㅋ

    Date2013.04.23 CategoryDevelop Byhooni Views15983
    Read More
  10. [css] z-index에 설정할 수 있는 최대값?

    Date2013.12.20 CategoryDevelop Byhooni Views15952
    Read More
  11. [ios] iOS In App Purchase #1 (코드 구현 전 웹 설정 작업)

    Date2013.11.20 CategoryDevelop Byhooni Views15909
    Read More
  12. [unix] 날짜 관련 쉘 명령어 (특정일 또는 +-시간, 날짜 계산된 값)

    Date2013.04.23 CategoryDevelop Byhooni Views15852
    Read More
Board Pagination Prev 1 ... 9 10 11 12 13 14 15 16 17 18 ... 71 Next
/ 71