Delete an outfile

I am trying to delete an outfile, Ive never really used the inFile outFile stuff before, so not sure if this would actually work or not. Is this a way of actually deleting the save

1
2
3
4
void Character::DeletePokemon()
{
	remove("Pokemon.dat");
}
Last edited on
It doesnt seem to be working. I call it like this.

PersonCharacterName.DeletePokemon()

That should work right.
Yes, assuming it compiles and links.

Replace the entire function Character::DeletePokemon() in your first post with this, and tell me what it prints:
1
2
3
4
5
6
7
8
9
10
11
# include <cerrno>
# include <cstdio>
# include <cstring>
# include <iomanip>
# include <iostream>
void Character::DeletePokemon() {
  std::string file("testfile.txt");
  if (remove(file.c_str())) 
    std::cerr << "error deleting " << std::quoted(file)
              << ": " << std::strerror(errno) << "\n";
}


If it prints nothing, then the call to remove() succeeded. If it did not, it will complain, hopefully with an error message describing why, although that is not required.
Last edited on
I got a weird error

Severity Code Description Project File Line Suppression State
Error C4996 'strerror': This function or variable may be unsafe. Consider using strerror_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details. Pokemon1 c:\users\k\desktop\pokemon1\pokemon1\characterclass.h 96
Oh, you're using MSVS.

Microsoft has apparently decided that std::strerror() can cause security problems, and is prohibiting us from using it as a result.

This decision is essentially arbitrary; they decided this (I assume) because strerror() is neither thread-safe nor reentrant. This isn't a problem here, but Microsoft decided to stop us anyway, just in case we didn't know what we were doing. Things like this are why I no longer write code for Microsoft platforms.

This is another way to do the same thing. I expect this to compile (famous last words):
1
2
3
4
5
6
7
8
9
10
11
# include <cerrno>
# include <cstdio>
# include <cstring>
# include <iomanip>
# include <iostream>
void Character::DeletePokemon() {
  std::string file("test/file.txt");
  if (std::remove(file.c_str())) 
    std::perror(file.c_str());
}
}

Last edited on
working, thanks a lot :)
Topic archived. No new replies allowed.