olexander_dan

Untitled

May 7th, 2019
288
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.18 KB | None | 0 0
  1. std::string getFilePath(const char& ioVar) {
  2.     std::string filePath = "";
  3.     if (ioVar == 'i') {
  4.         std::cout << "\nEnter the path to the input file: ";
  5.         std::cin.clear(); //clears the stream if ^z is pushed
  6.         getline(std::cin, filePath);
  7.         //if the input is clear -> read information from in.txt from the root folder
  8.         if (filePath.empty())
  9.             filePath = "D:/Studying/Programming/LABS/Laboratory Work 2.3 v.1/Laboratory Work 2.3 v.1/in.txt";
  10.         //if user didn't provided full adress -> find the file in the root folder
  11.         else if (filePath.find('\\') == std::string::npos and filePath.find('/') == std::string::npos)
  12.             filePath += ".txt";
  13.     } else {
  14.         std::cout << "\nEnter the path to the output file: ";
  15.         std::cin.clear();
  16.         getline(std::cin, filePath);
  17.         //if file path is empty -> save the output to the out.txt in the root folder
  18.         if (filePath.empty())
  19.             filePath = "D:/Studying/Programming/LABS/Laboratory Work 2.3 v.1/Laboratory Work 2.3 v.1/out.txt";
  20.         //if user didn't provided full adress -> create a new file in the root folder
  21.         else if (filePath.find('\\') == std::string::npos and filePath.find('/') == std::string::npos)
  22.             filePath += ".txt";
  23.     }
  24.     return filePath;
  25. }
Advertisement
Add Comment
Please, Sign In to add comment