How to rename a file using wstring?
c++, visual-c++
Solution
When working with `Visual Studio`, you usually work with wide-strings. In order to rename the file you can use `MoveFileEx`-function, you can rename the file like this.
std::wstring newFilename = tempFileName.c_str();
newFilename += _T("new.txt");
if(!MoveFileEx(tempFileName.c_str(), newFilename.c_str(), flags )){
//error handling if call fails
}
See here for the documentation.
Problem
How can I rename a file in c++? ``` rename(tempFileName.c_str(), tempFileName.c_str()+"new.txt"); ``` But `tempFileName` is of type `std::wstring`. But `rename()` functions accepts only `const char*` parameters.