title: Removing a file using remove();
body: <p>Trying to remove/delete a file using the function below. Unfortunately, it fails every time.
  Had cut many lines of code that seemed unrelated to the question.</p>
  <pre><code>int main()
  {
      Login();
  }
  </code></pre>
  <p>the function below checks the existence of the file. if exists, it can remove it.</p>
  <pre><code>void Login()
  {
      char name[20], password[20], filepassword[10], ID[10], id1[10];
      cout &lt;&lt; &quot;Login--&gt;\nEnter user-ID: &quot;;
      cin &gt;&gt; ID;        
      strcpy(id1, ID);   
      strcat(ID,&quot;.txt&quot;);   //ID is the name of the file (.txt format).
      ifstream inputfromfile;
      inputfromfile.open(ID);
      if(!inputfromfile)
      {
          cout &lt;&lt;&quot;\nInvalid ID.\n&quot;;
          exit(EXIT_FAILURE);
      }
  //IF FILE EXISTS, BELOW IT WILL BE EXECUTED
      cout &lt;&lt; &quot;Password: &quot;; cin &gt;&gt; password;
      inputfromfile filepassword;
      if (strcmp(password, filepassword) != 0) //if password doesn't match
      {
          cout&lt;&lt; &quot;Wrong Password.\n&quot;;
          perror(&quot;Password incorrect&quot;);
      }
      inputfromfile.close();
  
      cout &lt;&lt;&quot;\nEnter 5 to remove account.\n&quot;;
      int x; cin &gt;&gt; x;
      if (x == 5)
      {
          RemoveAccount(ID);
      }
  }
  </code></pre>
  <p>remove function. it deletes the file/ID (.txt) that exists in the same folder.</p>
  <pre><code>void RemoveAccount(char ID[])
  {
      if (remove(ID)!=0)
      {
          cout &lt;&lt; &quot;failed to delete!&quot;;
          perror(&quot;account remove failed&quot;);
      }
      else 
      {
          cout &lt;&lt; &quot;Successfully deleted!&quot;;
          exit(EXIT_SUCCESS);
      }
  }
  
  </code></pre>
  <p>But if i write <code>remove(&quot;jackson.txt&quot;)</code> instead of <code>remove(ID)</code>, it works successfully. jackson.txt exists in the same folder.</p>