Develop
2013.04.23 15:40
[c++][mfc] 파일 입출력 샘플 (한줄씩 읽어서 다른 파일에 쓰기)
조회 수 15060 댓글 0
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(); // 닫기 }
번호 | 분류 | 제목 | 글쓴이 | 날짜 | 조회 수 |
---|---|---|---|---|---|
285 | Develop | [ios] iOS에서 디바이스 종류 알아오기 | hooni | 2014.05.24 | 3762 |
284 | Develop | [ios] SQLite 사용하기(튜토리얼) + 샘플코드 | hooni | 2014.03.28 | 3754 |
283 | Develop | [ios] URL 파라미터 파싱~ | hooni | 2014.05.12 | 3742 |
282 | Develop | [ios] UIWebView 캐쉬 삭제 | hooni | 2014.04.08 | 3712 |
281 | Develop | [ios] 유용한 매크로 | hooni | 2014.03.26 | 3703 |
280 | Etc | 영어. 불규칙 동사 정리 | hooni | 2017.10.04 | 3672 |
279 | System/OS | [android] 초간단 HTTP, POST 전송 샘플 1 | hooni | 2017.02.16 | 3657 |
278 | Database | [mysql] 중복데이터 삭제하는 초간단 쿼리 | hooni | 2017.11.22 | 3570 |
277 | Develop | [js] jQuery 셀 병합 1 | hooni | 2014.09.23 | 3567 |
276 | Develop | [ios] 아이폰에서 진동(Vibrate) 기능 추가하기 | hooni | 2014.04.18 | 3539 |
275 | Develop | [android] dp, px 서로 변환 | hooni | 2016.10.21 | 3509 |
274 | Develop | [ios] NSString URL Encode/Decode (인코딩/디코딩) | hooni | 2014.05.02 | 3498 |