Advertisement
Guest User

load method

a guest
Dec 9th, 2019
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.32 KB | None | 0 0
  1. void load(string filename) {
  2.     std::string loading = "Loading File...";
  3.     wrapOut(&loading);
  4.     wrapEndPara();
  5.  
  6.     std::ifstream myFile(filename);
  7.     std::string content;
  8.  
  9.     while (!myFile.eof()){
  10.         getline(myFile, content);
  11.  
  12.         if (content.compare("Current_Room") == 0){
  13.             getline(myFile, content, ',');
  14.             std::cout << content << std::endl;
  15.         }
  16.         else if (content.compare("Inventory") == 0){
  17.             while (content.compare("end") != 0){
  18.                 getline(myFile, content, ',');
  19.                 if (content == "end" || content == "\nend"){
  20.                     break;
  21.                 }
  22.                 std::cout << content << std::endl;
  23.             }
  24.         }
  25.         else if(content.compare("Room_Inv") == 0){
  26.             while (content.compare("end") != 0){
  27.                 getline(myFile, content, ',');
  28.                 if (content == "end" || content == "\nend"){
  29.                     break;
  30.                 }
  31.                 std::cout << content;
  32.             }
  33.         }
  34.     }
  35.     std::cout << std::endl;
  36.  
  37.     if(myFile.fail()){
  38.         std::string failed = "Failed to load";
  39.         wrapOut(&failed);
  40.     }
  41.     else{
  42.         std::string saved = "Loaded save file!";
  43.         wrapOut(&saved);
  44.     }
  45.     myFile.close();
  46.     wrapEndPara();
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement