title: Why does my Loop no work properly?
body: <p>I have this code below that allows the user to amend file. The problem I have is that when I run through it once it works. But let say I want to open the txt file again it doesn't open.</p>
  
  <pre><code>string line, line2;
  string data, moduleID, input;
  int Choice;
  ifstream samsFile("SAMS.txt");
  fstream registeredModule("210CTStudentModule.txt");
  
  if(! samsFile){
      cout &lt;&lt; "Error Opening File" &lt;&lt; endl;
      return 0;
  }
  do{
      cout&lt;&lt;"HELLO AND WELCOME!!!"&lt;&lt;endl;
      cout&lt;&lt;"what do you want to do?"&lt;&lt;endl;
      cout&lt;&lt;"1: Check Registered Students"&lt;&lt;endl;
      cout&lt;&lt;"2: Register Student To Module"&lt;&lt;endl;
      cout&lt;&lt;"3: Open Registered Module File"&lt;&lt;endl;
      cout&lt;&lt;"4: Logout"&lt;&lt; endl;
      cin&gt;&gt;Choice;
      if(Choice==1){
              while(getline(samsFile,line)){
                  cout&lt;&lt;line&lt;&lt;endl;
              }
      }else if(Choice==2){
              vector&lt;string&gt;example;
              while(getline(samsFile,data)){
                  example.push_back(data);
              }
              cout&lt;&lt;"What Module Do You Want To Add?: "&lt;&lt;endl;
              cin.ignore();
              cin&gt;&gt;moduleID;
              vector&lt;string&gt;moduleCode;
              for(unsigned int j=0;j&lt;example.size();j++){
                  moduleCode.push_back(moduleID);
              }
              for(unsigned int k=0;k&lt;moduleCode.size();k++){
                  registeredModule&lt;&lt;moduleCode[k]&lt;&lt;" "&lt;&lt;example[k]&lt;&lt;"\n";
              }
      }else if(Choice==3){
          while(getline(registeredModule,line2)){
              cout&lt;&lt;line2&lt;&lt;endl;
          }
      }
  }while(Choice!=4);
  cout &lt;&lt; "Goodbye" &lt;&lt; endl;
  return 0;
  </code></pre>
  
  <p>Anyone has any idea why this is so?</p>