Hi, I'm in a beginning class in C++ and we need to make an assignment that inputs a file, prints it to the screen, and then prints it to the screen again with an underscore every 5 blanks. I got the last part to work, but I can't get it to print to the screen twice once without the underscores and once with the underscores.
It is also a requirement to use this in my program, and I'm not sure where it will go:
Input.clear(); // reset read pointer to very beginning of file
Input.seekg(0L, ios::beg);
Any help would be greatly appreciated.
#include <iostream> // include standard I/O library
#include <fstream> // include standard file library
#include <iomanip> // include IO manipulators
#include <string> // include C++ string class
#include <cctype> //
using namespace std; // access standard namespace
int main ()
{
ifstream Input;
string fileName;
// variables
char name;
char last = ' ';
int blank = 1;
// book operators
bool is5blank = false;
bool print = false;
// constants
const string UNDERLINE = " ________";
cout << "Please enter the file name with .txt at the end" << endl;
cin >> fileName;
cout << "\n================" << endl;
cout << "ECHOPRINTED TEXT" << endl;
cout << "================" << endl << endl;
Input.open(fileName.c_str());
while (!Input)
{
cout << "Please re-enter the file name" << endl;
cin >> fileName;
cout << endl;
Input.open(fileName.c_str());
}
Input.clear(); // reset read pointer to very beginning of file
Input.seekg(0L, ios::beg);
cout << endl << endl;
while ((name = Input.get()) != EOF)
{
if (isalpha(name))
{
if(blank == 0)
{
if(print == false)
{
cout << UNDERLINE;
print = true;
}
}
else
cout << name;
}
else
{
if(isalpha(last))
blank++;
if(blank == 5)
{
blank = 0;
print = false;
}
cout << name;
}
last = name;
}
Input.close();
return 0;
}