-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathExer08_05.cpp
49 lines (49 loc) · 925 Bytes
/
Exer08_05.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
using std::istream;
using std::ostream;
using std::ifstream;
using std::cout;
using std::cerr;
using std::endl;
using std::string;
using std::vector;
istream& restoreData(ifstream& is, const string &ifile, vector<string> &v)
{
string str;
is.open(ifile);
if(is)
{
while(is >> str)
{
v.push_back(str);
}
}
return is;
}
int main(int argc, char* argv[])
{
ifstream in;
vector<string> vec;
if(argc == 2)
{
restoreData(in, argv[1], vec);
}
// basic error prompt.
else if(argc < 2)
{
cerr << "Please offer a file name!" << endl;
return -1;
}
else
{
cerr << "Too many input arguments!" << endl;
return -1;
}
if(!vec.empty())
for(const auto &s : vec)
cout << s << endl;
return 0;
}