Is there a simple way to strip away the starting ./ of a path. For example: I have a path ./x/y and i want to convert it to x/y (without the first dot and slash). Is there a standard way of doing it?
#include <iostream>
#include <filesystem>
namespace filesystem = std::filesystem;
int main() {
auto path = filesystem::path{"./x/y"};
std::cout << path << std::endl;
std::cout << ???? << std::endl; // How do I do this?
}
Apparently the problem could be solved with std::filesystem::relative():
#include <iostream>
#include <filesystem>
namespace filesystem = std::filesystem;
int main() {
auto path = filesystem::path{"./x"};
std::cout << path << std::endl;
std::cout << filesystem::relative(path, "./") << std::endl; //
}
Produces
"./x"
"x"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With