std::string
オブジェクトにパスが保存されているファイルを削除します。 <cstdio>
にremove()
がありますが、引数にはconst char *
が必要です。 文字列オブジェクトを入力とする関数のように、ファイルを削除する直接的な方法はありますか?C++でのファイル削除
std::string filename = ...
remove(filename.c_str());
std::string
オブジェクトにパスが保存されているファイルを削除します。 <cstdio>
にremove()
がありますが、引数にはconst char *
が必要です。 文字列オブジェクトを入力とする関数のように、ファイルを削除する直接的な方法はありますか?C++でのファイル削除
std::string filename = ...
remove(filename.c_str());
あなたはc_str()メソッドを使うことができます:
std::string somePath("/lib/");
remove(somePath.c_str());
を定義することができますについてどのよう
:もちろん
string fileName;
//...
remove(fileName.c_str());
、あなたは常にstd::string
オブジェクトがc_str()
メソッドを介してconst char*
表現をご提供します
int remove(std::string const& fileName)
{
return remove(fileName.c_str());
}
std::string
std::string
のconst char *
を返しますc_str()
と呼ばれる方法があります。それを利用してください!