Turbo-C
C++Builder  |  Delphi  |  FireMonkey  |  C/C++  |  Free Pascal  |  Firebird
볼랜드포럼 BorlandForum
 경고! 게시물 작성자의 사전 허락없는 메일주소 추출행위 절대 금지
터보-C 포럼
Q & A
FAQ
팁&트릭
강좌/문서
자료실
Lua 게시판
볼랜드포럼 홈
헤드라인 뉴스
IT 뉴스
공지사항
자유게시판
해피 브레이크
공동 프로젝트
구인/구직
회원 장터
건의사항
운영진 게시판
회원 메뉴
북마크
볼랜드포럼 광고 모집

C/C++ Q/A
[176] Re:이렇게 파일을 읽을 수도 있습니다.
이상헌 [] 4774 읽음    2001-12-25 00:16

: #include <iostream.h>
: #include <fstream.h>
: #include <stdlib.h>
:
: main()
: {
:     int DATA_SIZE;
:     int* data_array;
:     ifstream data_file("numbers.txt");
:     int i;
:
:     // 만약 화일이 없거나, 문제가 생기게 되면,, true, 아니면 false
:     if (data_file.bad())
:     {
:         cerr<<"Error : Could not open numbers.txt\n";
:         exit(8);
:     }
:
:        // 데이터 전체 개수 읽기
:        double dtemp;
:        for(i=0; data_file >> dtemp; ++i); DATA_SIZE = i; data_file.close();
:
:        data_array = new int[DATA_SIZE];
:
:        data_file.open("numbers.txt");
:     for(i=0; data_file >> data_array[i] ;i++); data_file.close();  
:        
:
:     int total;    // 숫자의 총합
:
:     total = 0;
:
:     for(i=0;i<DATA_SIZE;++i)
:        total+=data_array[i];
:        
:     cout << "Total of all the numbers is" << total << '\n';
:          
:        delete[] data_array;
:     return 0;
: }

+ -

관련 글 리스트
31 파일 읽어오는 프로그램.. 3298 2001/11/23
176     Re:이렇게 파일을 읽을 수도 있습니다. 이상헌 4774 2001/12/25
175     Re:파일 읽어오는 프로그램.. 이상헌 2728 2001/12/25
34     Re:파일 읽어오는 프로그램.. 나그네 4029 2001/11/24
Google
Copyright © 1999-2015, borlandforum.com. All right reserved.