小编van*_*yen的帖子

std::filesystem::exists 函数在 Windows 10 上无法正常工作

我用 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命令,我只使用用户权限运行它。

c++ windows c++17

6
推荐指数
0
解决办法
365
查看次数

C风格投射到相同的层次水平

我有以下代码段:

#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)

c++ casting

0
推荐指数
1
解决办法
75
查看次数

标签 统计

c++ ×2

c++17 ×1

casting ×1

windows ×1