使用Remove-C++删除文件

Deleting a File using Remove - C++

本文关键字:文件 删除 Remove-C++ 使用      更新时间:2023-10-16

我对C++还比较陌生,我想知道如何删除一个文件——基于给它传递一个目录。我试过这样做,但没用。代码:

    remove (".\Players\" + getPlayerUsername() + "\Balance.txt");

错误:

    11  IntelliSense: no instance of overloaded function "remove" matches the argument list
        argument types are: (std::string)   

我正在使用Visual Studio 2013(我不喜欢)。

谢谢:-)KJ

更改为

remove ((".\Players\" + getPlayerUsername() + "\Balance.txt").c_str());

===编辑===

警告显示您的表达式求值为std::string,而remove需要const char*std::string有一个方法.c_str(),它返回指向字符串的const char*指针。