Does Remove not work with file directories?

I'm using the code found on the site here:


1
2
3
4
5
6
7
8
9
10
11
//* remove example: remove myfile.txt */
#include <stdio.h>

int main ()
{
  if( remove( "myfile.txt" ) != 0 )
    perror( "Error deleting file" );
  else
    puts( "File successfully deleted" );
  return 0;
}


I replaced the myfile.txt with the directory of the file I want deleted.

"C:\SOUNDS\savegame.dat"

It returns: Error deleting file. No such file or directory exists.

I've triple checked the directory. Its correct. I must be using this incorrectly. How?
Last edited on
Are you using double slashes?

"C:\\SOUNDS\\savegame.dat"
That did it, I didn't see any mention of that in the article so I wasn't aware that was necesary. Is that only for remove?

Thanks for the help.
Anytime you want to put a backslash in a string you must put two since the first one is the escape sequence.
http://en.cppreference.com/w/cpp/language/escape
That's why you should never use backslashes for paths. All operating systems support forward slashes, so always use forward slashes for paths. Only some operating systems support backslashes, and they have to be escaped, so don't use them.
I see now, that makes sense, appreciate the input.
Topic archived. No new replies allowed.