我用 c++17 msvc 编写了一些代码,如下所示:
#include <filesystem>
#include <iostream>
int main()
{
using namespace std::filesystem;
std::wstring s = L"c:\\windows\\system32\\applicationframehost.exe";
path p(s);
std::cout << absolute(p) << std::endl;
std::cout << exists(p) << std::endl;
std::cin.get();
return 0;
}
Run Code Online (Sandbox Code Playgroud)
并在 Windows 10 上运行它。应用程序打印 0 -> 表示该文件不存在。但它确实存在,当我尝试使用 Cygwinls -l命令时,它显示了一个很好的结果:
@myuser> ls -l c:\windows\system32\applicationframehost.exe
-rwxr-xr-x 2 cody.nguyen 1049089 69800 Apr 12 2018 'c:\windows\system32\applicationframehost.exe'
你能解释一下为什么以及如何从代码解决这个问题吗?谢谢,P/S:exists(p)除了C:\Windows\System32\. 我只是尝试使用管理员/系统/用户权限运行我的应用程序,但得到了相同的结果。使用ls -l命令,我只使用用户权限运行它。
我有以下代码段:
#include <iostream>
using namespace std;
class IA
{
public:
virtual void printA() = 0;
virtual ~IA(){};
};
class IB
{
public:
virtual void printB() = 0;
virtual ~IB(){}
};
class IC : public IA, public IB
{
public:
void printA() {cout << "hello world a" << endl; }
void printB() {cout << "hello world b" << endl; }
};
void func(IB* p)
{
p->printB();
}
int main()
{
IA* p = new IC;
p->printA();
cout << "cast to ib" …Run Code Online (Sandbox Code Playgroud)