title: Replace line in txt file c++
body: <p>I just wondering cause i have a text file containing <strong>STATUS:USERID:PASSWORD</strong> in <strong>accounts.txt</strong></p>
  
  <p>example it would look like this:</p>
  
  <blockquote>
    <blockquote>
      <p>OPEN:bob:askmehere:</p>
      
      <p>OPEN:john:askmethere:</p>
      
      <p>LOCK:rob:robmypurse:</p>
    </blockquote>
  </blockquote>
  
  <p>i have a user input in my main as such user can login 3x else status will change from OPEN to LOCK</p>
  
  <p>example after 3 tries of <strong>john</strong></p>
  
  <p><strong>before:</strong></p>
  
  <blockquote>
    <blockquote>
      <p>OPEN:bob:askmehere:</p>
      
      <p>OPEN:john:askmethere:</p>
      
      <p>LOCK:rob:robmypurse:</p>
    </blockquote>
  </blockquote>
  
  <p><strong>after:</strong></p>
  
  <blockquote>
    <blockquote>
      <p>OPEN:bob:askmehere:</p>
      
      <p>LOCK:john:askmethere:</p>
      
      <p>LOCK:rob:robmypurse:</p>
    </blockquote>
  </blockquote>
  
  <p>what i have done is:</p>
  
  <pre><code>void lockUser(Accounts&amp; in){
  // Accounts class consist 3 attributes (string userid, string pass, status)
  
  ofstream oFile;
  fstream iFile;
  string openFile="accounts.txt";
  string status, userid, garbage;
  Accounts toupdate;
  
  oFile.open(openFile);
  iFile.open(openFile);
  
      while(!iFile.eof()){
  
          getline(iFile, status, ':');
          getline(iFile, userid, ':');
          getline(iFile, garbage, '\n');
  
  
          if(userid == in.getUserId()){
  
              toupdate.setUserId(in.getuserId());
              toupdate.setPassword(in.getPassword());
              toupdate.setStatus("LOCK");
              break;
      }
  
      //here i should update the account.txt how do i do that?
      ofile.open(openFile);
  
      ofile&lt;&lt;toupdate.getStatus()&lt;&lt;":"&lt;&lt;toupdate.getUserId()":"&lt;&lt;toupdate.getPassword()&lt;&lt;":"&lt;&lt;endl;
  }
  </code></pre>