-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathputback.cpp
More file actions
65 lines (56 loc) · 1.83 KB
/
putback.cpp
File metadata and controls
65 lines (56 loc) · 1.83 KB
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
53
54
55
56
57
58
59
60
61
62
63
64
65
/*
* =====================================================================================
*
* Filename: putback.cpp
*
* Description: To understand the working of putback function in c++
*
* Version: 1.0
* Created: Wednesday 06 March 2013 04:14:20 IST
* Revision: none
* Compiler: gcc
*
* Author: Santosh (),
* Organization: ISSC
*
* =====================================================================================
*/
#include <iostream>
#include <fstream>
#include <stdlib.h>
using namespace std;
/*
* === FUNCTION ======================================================================
* Name: main
* Description: To read the text and putback the pointer to read it again
* ABCD putback on B
* reads ABBCD
* =====================================================================================
*/
int
main ( int argc, char *argv[] )
{
cout<<"Use of putback in c++"<<endl;
ofstream fout("MyFile1");
fout<<"ABCDE";
fout.close();
ifstream fin("MyFile1");
if(fin == NULL) exit(0);
char ch;
fin.get(ch);
cout<<"Data read in "<<ch;
cout<<"Data read is "<<ch <<endl;
/*-----------------------------------------------------------------------------
* istream & putback (char ch) - It move the get pointer backward by one move
*-----------------------------------------------------------------------------*/
fin.putback(ch);
cout<<"After putback "<<ch;
/*-----------------------------------------------------------------------------
* putback has no effect if current value is not given
*-----------------------------------------------------------------------------*/
fin.putback('#');
cout<<"After putback "<<ch<<endl;
fin.get(ch);
cout<<"Data read "<<ch;
return EXIT_SUCCESS;
} /* ---------- end of function main ---------- */