File tree 1 file changed +75
-1
lines changed
1 file changed +75
-1
lines changed Original file line number Diff line number Diff line change @@ -30,4 +30,78 @@ Some of the operators cannot be overloaded<br>
30
30
1 . Scope resolution operator (::)
31
31
1 . sizeof();
32
32
1 . Ternary Operators ( ? :)
33
- 1 .
33
+
34
+
35
+ ### File Handeling
36
+
37
+ ``` cpp
38
+ #include < iostream>
39
+ // provides ofstream and ifstream functionality
40
+ #include < fstream>
41
+ using namespace std ;
42
+
43
+ int main () {
44
+ //used to create a new file and write contents to it
45
+ ofstream myFile("./tempfiles/test.txt");
46
+
47
+ myFile << "Hello, world!" << endl;
48
+ myFile.close();
49
+
50
+ return 0;
51
+ }
52
+ ```
53
+
54
+ ``` cpp
55
+ #include < iostream>
56
+ #include < fstream>
57
+ using namespace std ;
58
+
59
+ int main () {
60
+ string stringOne;
61
+ ifstream myFile("./tempfiles/hello.txt");
62
+
63
+ while (getline(myFile, stringOne)) {
64
+ cout << stringOne;
65
+ }
66
+
67
+ myFile.close();
68
+
69
+ return 0;
70
+ }
71
+ ```
72
+
73
+ ### Fstream
74
+ This header file used for ofstream and ifstream in the program
75
+
76
+ ### ofstream
77
+ Used to create and write content in a file
78
+
79
+ ### ifstream
80
+ opening a file by name and display the data
81
+
82
+ ### getline
83
+ to read data from the file line by line by making use of string variable defined
84
+
85
+ ### close
86
+ closing the file that was opened to write the file contents into the file
87
+
88
+
89
+ ``` cpp
90
+ #include < iostream>
91
+ #include < fstream>
92
+ using namespace std ;
93
+
94
+ int main () {
95
+ ofstream filestream("helloThree.txt");
96
+
97
+ if(filestream.is_open()) {
98
+ filestream << "Line 1" << endl;
99
+ filestream << "Line 2" << endl;
100
+ filestream.close();
101
+ } else {
102
+ cout << "File has not been created" << endl;
103
+ }
104
+
105
+ return 0;
106
+ }
107
+ ```
You can’t perform that action at this time.
0 commit comments