-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfileHandling.cpp
47 lines (40 loc) · 1.04 KB
/
fileHandling.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
// https://www.geeksforgeeks.org/file-handling-c-classes/
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
/*
string input;
cout<<"Enter Something : "<<endl;
getline(cin, input);
*/
// Create a File
/*
try{
ofstream myFile("Test.txt", ios::app); // ios::out | ios::ate [fstream]
// myFile.open("Test.txt"); // Open the File
myFile<<input;
myFile.close();
cout<<"File Operation Successful";
}
catch(...){
cout<<"File Operation Unsuccessful";
}
*/
// Read File
try{
ifstream myFile("Test.txt", ios::in);
// myFile.open("Test.txt");
char output[100];
myFile.getline(output, 100);
myFile.close();
cout<<"The File Contents are : ";
puts(output);
cout<<"File Operation Successful";
}
catch(...){
cout<<"File Operation Unsuccessful";
}
return 0;
}