-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path3_fstream_basic.cpp
More file actions
53 lines (41 loc) · 929 Bytes
/
Copy path3_fstream_basic.cpp
File metadata and controls
53 lines (41 loc) · 929 Bytes
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
50
51
52
53
#include <iostream>
#include <fstream>
#include <vector>
using namespace std;
int main()
{
vector<int> nums;
ifstream ifile("C:\\CSCI104\\data.txt");
int x;
/*while( !ifile.fail() ) {
ifile >> x;
nums.push_back(x);
}
while(1) {
ifile >> x;
if(ifile.fail()) break;
nums.push_back(x);
}*/
// Extraction and check together
while(ifile >> x) {
nums.push_back(x);
}
//cout << nums[0] << endl;
//cout << nums[1] << endl;
//cout << nums[2] << endl;
vector<int>::iterator it;
for(it = nums.begin(); it != nums.end(); ++it)
{
cout << *it << endl;
}
ifile.close();
/*3 steps sequence is
a) Extarct from stream / file
b) Check for failure
c) Do the operation*/
ofstream ofile("C:\\CSCI104\\data2.txt");
ofile << "Hello Morning" << endl;
ofile << " 7 8 9" << endl;
ofile.close();
return 0;
}