Hello all,
I am working on a program that takes input from a file, removes extra white spaces and outputs the edited text to another file.
So far my program deletes 1 whitespace whether the whitespace should be deleted or not.
I have read about peek() and putback(). I am pretty sure I need to implement these two functions but quite frankly I am not sure how to go about doing this.
I don't want anyone to just give me the answer I would really appreciate it if someone gave me a hint as to where my logic went south or my structure or enlighten me about some predefined function you think I may not be aware of.
Any help is appreciated. Thank you.
-Arielle
#include <iostream>
#include <iomanip>
#include <fstream>
#include <cstdlib>
using namespace std;
void check_blank(ifstream& instream, ofstream& outstream);
int number = 0; //keeps track of how many spaces have been deleted
int main()
{
ifstream instream;
ofstream outstream;
bool t;
instream.open("hw4pr6input.txt"); //Open file: text to be edited
if(!instream.fail()) //Make sure file opened successfully
{
cout << "test from open";
//Call function that finds blanks and edits
}
else
{
cout << "File failed to open (1st)";
exit(1);
}
outstream.open("hw4pr6output.txt"); //Open file: edited text will go
if(!outstream.fail()) //Check if open failed
{
t = true;
check_blank(instream, outstream); //Call function to input edited text into file
}
else
{
cout << "File failed to open (2nd)";
exit(1);
}
cout << "Removed " …