Home / utk / cs102 / fa16 / labi / code_snippets / section2 / isstream.cpp
Directory Listing
isstream.cpp
namelist.txt
osstream.cpp
result.txt
string_reverse.cpp
strings_reverse.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
30
31
32
33
34
#include <iostream>
#include <string>
#include <fstream>
#include <sstream>

using namespace std;

int main() {
	string line;
	double value, total;
	int num_of_tests;
	ifstream fp;
	fp.open("namelist.txt");
	getline(fp, line);
	fp.close();
	
	istringstream sin;
	sin.str(line);
	
	string fname, lname;
	
	sin >> fname >> lname;
	cout << lname << ", " << fname << endl;
	total = 0;
	num_of_tests = 0;

	while (sin >> value) {
		total += value;
		num_of_tests++;
	}
	total /= num_of_tests;

	cout << "Total: " << total << endl;
}