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 num,
  9. vector <string> vec_words)
  10. {
  11. for ( int i=0; i<num; i++)
  12. {
  13. out_file << "-" << endl;
  14. }
  15. for ( int i=0 ;i < vec_words.size(); i++)
  16. {
  17. int line_counter = 0;
  18. if ( line_counter == 0 )
  19. {
  20. out_file << "| ";
  21. }
  22.  
  23. else
  24. {
  25. if ( line_counter + vec_words[i].size() <= num )
  26. {
  27. line_counter = line_counter + vec_words[i].size();
  28. out_file << vec_words[i] << " ";
  29. }
  30.  
  31. else
  32. {
  33. for ( int i = line_counter; i< num; i++)//or num-1.
  34. {
  35. out_file << " ";
  36. }
  37. out_file << "|" << endl;
  38. }
  39. }
  40. }
  41. }
  42.  
  43. void flush_right ( ifstream file, int num )
  44. {
  45. }
  46.  
  47. void full_justify ( ifstream file, int num )
  48. {
  49. }
  50.  
  51.  
  52.  
  53.  
  54.  
  55.  
  56. int main( int argc, char* argv[])
  57. {
  58. ifstream file(argv[1]);
  59. if ( !file )
  60. {
  61. cerr << "Can't open " << argv[1] << " to read. \n";
  62. return 1;
  63. }
  64. string words;
  65. vector <string> vec_words;
  66. while ( file >> words )
  67. {
  68. vec_words.push_back(words);
  69. }
  70.  
  71.  
  72. ofstream out_file( argv[2]);
  73. if ( !out_file)
  74. {
  75. cerr << " Can't open " << argv[2] << " to write.\n";
  76. return 1;
  77. }
  78.  
  79. int number = atoi(argv[3]);
  80. string name = argv[4];
  81.  
  82.  
  83. if ( name == "flush_left" )
  84. flush_left ( out_file, number, vec_words );
  85.  
  86.  
  87. }
  88.  
  89.