Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit caea1ae

Browse files
authored
Add files via upload
1 parent aa9acbc commit caea1ae

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+1037
-0
lines changed

file_handling/appending.cpp

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#include <iostream>
2+
#include <fstream>
3+
4+
using namespace std;
5+
6+
int main()
7+
{
8+
fstream file("type2.txt", ios::in | ios::out | ios::app);
9+
10+
if (!file.is_open())
11+
{
12+
cout << "error to opening this file";
13+
}
14+
else
15+
{
16+
cout << "file is open __" << endl;
17+
cout << "wrting to the file" << endl;
18+
19+
file << "Lorem ipsum dolor sit amet, consectetur adipiscing elit."<<endl;
20+
file <<"Ut sed massa erat.Sed quam mauris,"<<endl;
21+
file << "iaculis cursus nibh.Morbi vel ligula massa.Aenean eget lor"<<endl;
22+
23+
file.seekg(0);
24+
cout<<"reading of the file";
25+
string line;
26+
while (file.good())
27+
{
28+
getline(file, line);
29+
cout<<line<<endl;
30+
}
31+
32+
33+
34+
}
35+
36+
return 0;
37+
}
38+
39+
// ios::app :-
40+
// by using this function, file will be created if there is no anny file of the same name, actually this function
41+
// is help us to avoid the use less error
42+
43+
// ham jitni martaba is code ko run kre gein yw utni dafa hi create ya write kre ga file ko means hamay file me
44+
// lines ziyada hi milay gi

file_handling/appending.exe

52.4 KB
Binary file not shown.

file_handling/binary_files.cpp

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#include <iostream>
2+
#include <fstream>
3+
#include <cstring>
4+
5+
using namespace std;
6+
7+
int main()
8+
{
9+
char input[100];
10+
strcpy(input, "learning the more");
11+
12+
fstream file("type.bin", ios::binary | ios::in | ios::out | ios::trunc);
13+
14+
if (!file.is_open())
15+
{
16+
cout << "error" << endl;
17+
}
18+
else
19+
{
20+
int len = strlen(input);
21+
for (int i = 0; i < len; i++)
22+
{
23+
file.put(input[i]);
24+
}
25+
26+
file.seekg(0);
27+
char ch;
28+
while (file.good())
29+
{
30+
file.get(ch);
31+
cout << ch;
32+
}
33+
}
34+
return 0;
35+
}

file_handling/binary_files.exe

50.6 KB
Binary file not shown.

file_handling/copy_file.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#include <iostream>
2+
#include <fstream>
3+
4+
using namespace std;
5+
6+
int main()
7+
{
8+
ifstream file("type.txt");
9+
ofstream file2("type2.txt");
10+
11+
string line;
12+
while (file.good())
13+
{
14+
getline(file, line);
15+
file2 << line << endl;
16+
}
17+
18+
file2.close();
19+
file.close();
20+
21+
return 0;
22+
}

file_handling/copy_file.exe

50.9 KB
Binary file not shown.

file_handling/file_pointers.cpp

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#include <iostream>
2+
#include<fstream>
3+
using namespace std;
4+
5+
int main()
6+
{
7+
ofstream file("type.txt");
8+
ifstream file2("type.txt");
9+
10+
11+
// using seekp() and tellp()
12+
13+
// cout<<file.tellp()<<endl;
14+
// file << "hello hadi";
15+
// cout<<file.tellp()<<endl;
16+
// file.seekp(-5, ios::end);
17+
// cout<<file.tellp()<<endl;
18+
// file << "faiz";
19+
// file.seekp(0, ios::beg);
20+
// file<<"hello";
21+
22+
// file.close();
23+
24+
// string line;
25+
// while(file2.good()){
26+
27+
// getline(file2, line);
28+
// cout<<line;
29+
30+
// }
31+
32+
33+
// using seekg() and tellg()
34+
35+
36+
return 0;
37+
}
38+
39+
// file pointers
40+
41+
// the are the outfile operators (ifstream)
42+
// seekp use to move tthe pointers
43+
// tellp use for tell about current loaction of the pionter
44+
45+
// input file ooperators are (ofstream)
46+
// seekg use for the reading from the specific words
47+
// tellg use for the tell about current loation
48+
49+
// SYNTEX
50+
// pointer(o, R)
51+
// offset means how mmuch u want to move an pointer by byte using (- or +)
52+
// refrence, where you want to start it i:e ios::beg, ios::end, ios::current
53+

file_handling/file_pointers.exe

48 KB
Binary file not shown.

file_handling/get_out.cpp

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#include <iostream>
2+
#include<fstream>
3+
using namespace std;
4+
5+
int main()
6+
{
7+
fstream file("type.txt", ios::in | ios::out);
8+
if(!file.is_open())
9+
{
10+
cout<<"error";
11+
}
12+
else
13+
{
14+
// cout<<file.tellg()<<endl; // tellg get
15+
// string line;
16+
// file.seekg(2); // starting from teaching ---> aching
17+
// getline(file, line);
18+
// cout<<line;
19+
20+
// cout<<file.tellp()<<endl;
21+
// file << "hello dearest";
22+
// cout<<file.tellp()<<endl; // tellp (put) only works when we are using the ofstream function
23+
24+
// file.seekp(5); // we can set the position, ios::beg, ios::in, ios::end
25+
// file <<" helloowwww";
26+
// cout<<file.tellp()<<endl;
27+
28+
cout<<file.tellg()<<endl;
29+
cout<<file.tellp()<<endl;
30+
31+
file.seekp(2);
32+
33+
cout<<file.tellg()<<endl;
34+
cout<<file.tellp()<<endl;
35+
36+
}
37+
return 0;
38+
}
39+
40+
41+
42+

file_handling/get_out.exe

51.1 KB
Binary file not shown.

0 commit comments

Comments
 (0)