: #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;
: }
|