如何使用std::string作为Const Char参数



我试图使用std::rename()函数来移动.docx文件,但是,文件的名称可能会有所不同。我如何在std::rename()中使用std::string,使其不必是硬编码的文件路径,如std::rename(filepath, destination);?

我不知道您想如何填充所讨论的字符串,但是您可以这样做:

std::string fromName {"whatever you're going to do"};
std::string toName {"whatever you're going to do"};
std::rename(fromName.c_str(), toName.c_str());

最新更新