路径规范中的两个点如何工作
How do two dots in work in path specifications
在这个例子中
#include <iostream>
#include <experimental/filesystem>
namespace fs = std::experimental::filesystem;
int main()
{
fs::path p = fs::path("..") / ".." / "AppData";//What is it?
std::cout << "Current path is " << fs::current_path() << '\n'
<< "Canonical path for " << p << " is " << fs::canonical(p) << '\n';
}
什么是 ".."
,它是如何工作的?
.. 是父目录,如果您在 /home/user/kat 并转到 .. 您将在 /home/user.
例如这样的代码:
fs::path parentPath = fs::current_path() / "..";
std::cout << parentPath << " → " << fs::canonical(parentPath) << std::endl;
将产生此输出(在我的 PC 上):
"/home/kamil/Pulpit/build/.." → "/home/kamil/Pulpit"
在这个例子中
#include <iostream>
#include <experimental/filesystem>
namespace fs = std::experimental::filesystem;
int main()
{
fs::path p = fs::path("..") / ".." / "AppData";//What is it?
std::cout << "Current path is " << fs::current_path() << '\n'
<< "Canonical path for " << p << " is " << fs::canonical(p) << '\n';
}
什么是 ".."
,它是如何工作的?
.. 是父目录,如果您在 /home/user/kat 并转到 .. 您将在 /home/user.
例如这样的代码:
fs::path parentPath = fs::current_path() / "..";
std::cout << parentPath << " → " << fs::canonical(parentPath) << std::endl;
将产生此输出(在我的 PC 上):
"/home/kamil/Pulpit/build/.." → "/home/kamil/Pulpit"