-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathExer08_10.cpp
37 lines (37 loc) · 860 Bytes
/
Exer08_10.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
#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
#include <vector>
using std::cout;
using std::cerr;
using std::endl;
using std::ifstream;
using std::istringstream;
using std::string;
using std::vector;
int main(int argc, char *argv[])
{
if(argc != 2)
{
cerr << "Wrong input!" << endl;
return -1;
}
ifstream input(argv[1]);
string line, stmp;
vector<string> text;
while(getline(input, line))
{
text.push_back(line);
}
for(const auto &s : text)
{
istringstream is(s); // element in text is a line of string, not a word
while(is >> stmp) // read each word in a line
{
cout << stmp << " "; // output each word
}
cout << endl; // this way the output is the completely the same as the input file
}
return 0;
}