1. #include <iostream>
  2. #include <fstream>
  3. #include <string>
  4. #include <vector>
  5. #include "stdlib.h"
  6. using namespace std;
  7.  
  8. void flush_left ( ofstream &out_file, int width,
  9. vector <string> v1)
  10. {
  11.  
  12. int new_line = 0;
  13. int line_size =0;
  14. for ( int i =0; i< width+4; i++)
  15. {
  16. out_file << "-";
  17. }
  18. out_file << endl;
  19.  
  20.  
  21. for ( int i = 0; i < v1.size() ;i++)
  22. {
  23. if ( new_line == 0)
  24. {
  25. line_size = line_size + v1[i].size()+1;
  26. out_file << "| " << v1[i];
  27. new_line = 1;
  28. cout << "1" << v1[i] << endl;
  29.  
  30. }
  31. else
  32. {
  33. if ( line_size + v1[i].size()+1 <= width)
  34. {
  35. line_size = line_size + v1[i].size()+1;
  36. out_file << " " << v1[i];
  37. new_line = 1;
  38. cout << "2" << v1[i] << endl;
  39. }
  40. else
  41. {
  42.  
  43. for ( int j = line_size; j < width+4; j++)
  44. {
  45. out_file << " ";
  46. }
  47. out_file << "|" << endl;
  48. out_file << "| " << v1[i];
  49. line_size = v1[i].size()+1;
  50. new_line = 1;
  51. cout << "3" << v1[i] << endl;
  52. }
  53. }
  54. }
  55.  
  56. for ( int i=0; i< width-line_size; i++)
  57. {
  58. out_file << " ";
  59. }
  60. out_file << "|";
  61.  
  62. out_file << endl;
  63. for ( int i =0; i< width+4; i++)
  64. {
  65. out_file << "-";
  66. }
  67. }
  68.  
  69. void flush_right ( ifstream file, int num )
  70. {
  71. }
  72.  
  73. void full_justify ( ifstream file, int num )
  74. {
  75. }
  76.  
  77.  
  78.  
  79.  
  80.  
  81.  
  82. int main( int argc, char* argv[])
  83. {
  84. ifstream file(argv[1]);
  85. if ( !file )
  86. {
  87. cerr << "Can't open " << argv[1] << " to read. \n";
  88. return 1;
  89. }
  90. string words;
  91. vector <string> vec_words;
  92. while ( file >> words )
  93. {
  94. vec_words.push_back(words);
  95. }
  96.  
  97.  
  98. ofstream out_file( argv[2]);
  99. if ( !out_file)
  100. {
  101. cerr << " Can't open " << argv[2] << " to write.\n";
  102. return 1;
  103. }
  104.  
  105. int number = atoi(argv[3]);
  106. string name = argv[4];
  107.  
  108.  
  109. if ( name == "flush_left" )
  110. flush_left ( out_file, number, vec_words );
  111.  
  112.  
  113. }
  114.  
  115.  
  116.