Question: C++ input stream classes haave two member functions,unget() and putback(), thatcan be used toundo an operation performed by the get () function. Research these functions

C++ input stream classes haave two member functions,unget() and putback(), thatcan be used to"undo" an operation performed by the get () function. Research these functions son the internet, and then use one of them to rewrite program 13-9without using the peek () function.

I am using viusal studios 2017

please help, I have tried everything! Thanks in advace

PROGRAM 13.9:

//This program demonstrates the peek member function.

#include

#include

#include

using namespace std;

int main()

{

//Variables needed to read characters and numbers

char ch;

int number;

//Variables for file handling

string fileName;

fstream inFile,outFile;

//Open the file to be modified

cout << "Enter a file name:";

cin >> fileName;

inFile.open(fileName.c_str(), ios : : in);

if (!inFile)

{

cout << "Cannot open file" << fileName;

return 1;

}

//Open thefile to receive themodifed copy

outFile.open(modified.txt",ios::out);

if(!outFile)

{

cout<<"Cannot open the output file.";

return 2;

}

//Copy the input file one character at a time

//except numbers in the input file must have 1

//added to them

//Peek at the first character

ch = inFile.peek();

while (ch != EOF)

{

//Examine current character

if (isdigit(ch))

{

//Numbers should be read with >>

inFile >> number;

outFile << number+1;

}

else

{

//Just a simple character, read it and copy it

ch = inFile.get();

outFile << ch;

}

//Peek at the next character from input file

ch = inFile.peek();

}

//Close the files

inFile.close();

outfile.close();

return 0;

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!