-
Notifications
You must be signed in to change notification settings - Fork 0
/
53_tellp_tellg.cpp
52 lines (46 loc) · 1.17 KB
/
53_tellp_tellg.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
48
49
50
51
52
//1-> tellg()-
//-defined in istream class
//-returns the position of current character in the input stream
//2-> tellp()-
//-defined in ostream class
//-returns the position of current character in the output stream
// use of tellg() - in reading from a file
/*
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
ifstream fin;
fin.open("my_file6.txt");
int pos;
char ch;
pos = fin.tellg(); // initially pointing i =0
cout << pos << endl;
fin >> ch;
pos = fin.tellg(); // now it points next character i.e; i =1
cout << pos << endl;
fin >> ch;
pos = fin.tellg(); // now it points next character i.e; i =2
cout << pos << endl;
fin.close();
return 0;
}
*/
// use of tellp() - in writting a file
#include<iostream>
#include<fstream>
using namespace std ;
int main ()
{
ofstream fout ;
fout.open("my_file7.txt" , ios :: app);
int pos ;
pos = fout.tellp(); // initially it points position = 0
cout<<pos<<endl;
fout<< "vaibhav" ;
pos = fout.tellp(); // not it points position = 7
cout<<pos<<endl;
fout.close();
return 0;
}