davemx_5

Untitled

May 17th, 2013
28
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.45 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include "Translator.h"
  4.  
  5. using namespace std;
  6.  
  7. // maximum number of characters in a line of the text
  8. const int MAXLINE=1000;
  9. int main(int argc, char *argv[])
  10. {
  11. if (argc<2)
  12. {
  13. cout << "No story file specified." << endl;
  14. return -1;
  15. }
  16.  
  17. fstream infile;
  18. infile.open(argv[1], ios::in);
  19.  
  20. if (infile.fail())
  21. {
  22. cout << "Could not open the story file." << endl;
  23. return -1;
  24. }
  25.  
  26. Translator translator("englishtoelvish.txt");
  27. fstream outfile;
  28. outfile.open("story_in_elvish.txt", ios::out);
  29. if (outfile.fail())
  30. {
  31. cout << "Could not open the output file." << endl;
  32. return -1;
  33. }
  34.  
  35. char english_line[MAXLINE], elvish_line[MAXLINE];
  36.  
  37. // Translate the story into Elvish
  38. while (!infile.fail())
  39. {
  40. infile.getline(english_line, MAXLINE, '\n');
  41. if (!infile.fail())
  42. {
  43. translator.toElvish(elvish_line, english_line);
  44. outfile << elvish_line << endl;
  45. }
  46. }
  47. outfile.close();
  48. infile.close();
  49.  
  50. // Read the translated story and re-translate into English
  51. infile.open("story_in_elvish.txt", ios::in);
  52. outfile.open("story_backto_english.txt", ios::out);
  53. while (!infile.eof())
  54. {
  55. infile.getline(elvish_line, MAXLINE, '\n');
  56. if (!infile.fail())
  57. {
  58. translator.toEnglish(english_line, elvish_line);
  59. outfile << english_line << endl;
  60. }
  61. }
  62.  
  63. infile.close();
  64. outfile.close();
  65. }
Advertisement
Add Comment
Please, Sign In to add comment