Home / utk / cs102 / fa16 / labi / code_snippets / section1 / student_info.cpp
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
30
31
32
33
34
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>

using namespace std;

int main() {
	string filename;
	
	//Request filename
	cout << "Input filename: ";
	cin >> filename;

	ifstream fp;
	fp.open(filename);
	
	//Get the first line of the file
	string line;
	getline(fp, line);
	
	fp.close();

	istringstream sin;
	sin.str(line);

	string firstname, lastname;

	sin >> lastname >> firstname;
	
	//Print
	cout << "First Name: " << firstname << endl;
	cout << "Last  Name: " << lastname  << endl;
}