Advertisement
Abir_Ahsan

File task

Jun 13th, 2020
43
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. void fileInput()
  2. {
  3. ifstream f_in;
  4.  
  5. int choice3;
  6. string loc, line;
  7. printf("\nEnter File location: ");
  8. cin >> loc;
  9.  
  10. f_in.open(loc.c_str());
  11.  
  12. if (f_in.is_open())
  13. {
  14. while (getline(f_in,line))
  15. {
  16. printf("\n1. Convert to Prefix \n");
  17. printf("2. Convert to Postfix \n");
  18.  
  19. printf("\nEnter your choice:");
  20. cin >> choice3;
  21.  
  22. if (choice3 == 1)
  23. {
  24. prefixConverter(line);
  25. }
  26. else if (choice3 == 2)
  27. {
  28. postfixConverter(line);
  29. }
  30.  
  31. }
  32. }
  33. else
  34. {
  35. std::cout << "Unable to open file" << std::endl << std::endl;
  36. }
  37.  
  38. f_in.close();
  39.  
  40. ofstream f_out;
  41. f_out.open(loc.c_str());
  42.  
  43. if (choice3==1)
  44. {
  45. f_out << result1 << endl;
  46. cout << "Output written in File." << endl;
  47. result1.clear();
  48. result2.clear();
  49. }
  50.  
  51. else if (choice3==2)
  52. {
  53. f_out << result2 << endl;
  54. cout << "Output written in File." << endl;
  55. result1.clear();
  56. result2.clear();
  57. }
  58. f_out.close();
  59. }
Advertisement
Advertisement
Advertisement
RAW Paste Data Copied
Advertisement