Directory Listing | |
---|---|
array_reference.cpp
|
|
getline.cpp
|
|
isstream.cpp
|
|
namelist.txt
|
|
numbers.txt
|
|
osstream.cpp
|
|
recordgen.c
|
|
result2.txt
|
|
result4.txt
|
|
student_info.cpp
|
|
sum.cpp
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
using namespace std;
int main() {
string line;
ifstream fp;
fp.open("numbers.txt");
getline(fp, line);
fp.close();
istringstream sin;
sin.str(line);
double total = 0,
value;
int num_of_entries = 0;
while (sin >> value) {
total += value;
num_of_entries++;
}
total /= num_of_entries;
cout << total << endl;
}