#include <iostream>
#include <fstream>
#include <vector>
using namespace std;
void flush_left ( vector<string> v1, int width)
{
ofstream out_file ( "flush_left.txt");
// Outputs the first line, " -----".
for ( int i =0; i< width+4; i++)
{
out_file << "-";
}
out_file << endl;
int nWidth = width;
int new_line = 0;
int line_size =0;
for ( int i = 0; i < v1.size() ;i++)
{
line_size = line_size + v1[i].size();
if ( new_line == 0)
{
out_file << "| " << v1[i];
new_line = 1;
}
else
{
if ( line_size + 1 <= nWidth)
{
out_file << " " << v1[i];
// nWidth = nWidth- v1[i].size();
new_line = 1;
line_size++;
}
else
{
for ( int j = line_size - v1[i].size(); j < nWidth + 1; j++)
{
out_file << " ";
}
out_file << "|" << endl;
// nWidth = width;
out_file << "| " << v1[i];
line_size = v1[i].size();
new_line = 1;
}
}
}
for ( int j = line_size - v1[v1.size() - 1].size(); j < nWidth + 1; j++)
{
out_file << " ";
}
out_file << "|" << endl;
// nWidth = width;
for ( int i =0; i< width+4; i++)
{
out_file << "-";
}
}
int main()
{
cout << " What specified width do you want it " << endl;
cout << "to be displayed ? " << endl;
int width;
cin >> width;
ifstream read_file;
read_file.open( "file.txt" );
if (!read_file.is_open())
{
cout << " File not found " << endl;
}
vector<string> s_vector;
string input_string;
while (!read_file.eof())
{
read_file >> input_string;
s_vector.push_back( input_string);
}
flush_left ( s_vector, width);
return 0;
}