Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 9b6ac2f

Browse files
File Handling
1 parent 2ce961d commit 9b6ac2f

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

‎fileHandling.cpp‎

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
// https://www.geeksforgeeks.org/file-handling-c-classes/
2+
#include <iostream>
3+
#include <fstream>
4+
5+
using namespace std;
6+
7+
int main()
8+
{
9+
/*
10+
string input;
11+
cout<<"Enter Something : "<<endl;
12+
getline(cin, input);
13+
*/
14+
15+
// Create a File
16+
17+
/*
18+
try{
19+
ofstream myFile("Test.txt", ios::app); // ios::out | ios::ate [fstream]
20+
// myFile.open("Test.txt"); // Open the File
21+
myFile<<input;
22+
myFile.close();
23+
cout<<"File Operation Successful";
24+
}
25+
catch(...){
26+
cout<<"File Operation Unsuccessful";
27+
}
28+
*/
29+
30+
// Read File
31+
32+
try{
33+
ifstream myFile("Test.txt", ios::in);
34+
// myFile.open("Test.txt");
35+
char output[100];
36+
myFile.getline(output, 100);
37+
myFile.close();
38+
cout<<"The File Contents are : ";
39+
puts(output);
40+
cout<<"File Operation Successful";
41+
}
42+
catch(...){
43+
cout<<"File Operation Unsuccessful";
44+
}
45+
46+
return 0;
47+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /