If I have a file like this, everything works as expected:
#include <filesystem>
#include <iostream>
int main() {
std::filesystem::path o = "C:\\Windows\\write.exe";
auto s = o.parent_path();
std::cout << s << std::endl;
}
However I would like to use a line like this if possible:
filesystem::path o = "C:\\Windows\\write.exe";
I tried this but I get an error:
// using-declaration may not name namespace 'std::filesystem'
using std::filesystem;
and error with this too:
using namespace std::filesystem;
// error: 'filesystem' has not been declared
filesystem::path o = "C:\\Windows\\write.exe";
Is it possible to do what I am attempting?
You can use a namespace alias like
namespace filesystem = std::filesystem;
Here is a demonstrative program
#include <iostream>
namespace A
{
namespace B
{
int x;
}
}
int main()
{
namespace B = A::B;
B::x = 10;
std::cout << B::x << '\n';
return 0;
}
Its output is
10
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