title: Why does std::remove for file always return -1?
body: <p>I am trying to remove a file if exists. So first I test if the file exists and if it does I remove it using <code>std::remove</code>. test.json contains some json related txt in it. I also have <code>#include &lt;cstdio&gt;</code> included.</p>
  
  <pre><code>   std::string file_to_remove = "test.json";
     std::ifstream f(file_to_remove.c_str());
  
    if (f.good()) {
      int val = std::remove(file_to_remove.c_str());
      std::cout &lt;&lt; "\nRemoving file : " &lt;&lt; file_to_remove  &lt;&lt; " : ret val : " &lt;&lt; val&lt;&lt; std::endl;
    }
  </code></pre>
  
  <p>I was expecting the ret val to be <code>0</code> but I am getting <code>-1</code></p>
  
  <p>My current output is : </p>
  
  <blockquote>
    <p>Removing file : test.json : ret val : -1</p>
  </blockquote>
  
  <p>I have also made sure the file is closed.</p>