简体   繁体   English

无法在linux中执行文件

[英]Unable to execute a file in linux

I have created a program in which fopen() is being used.我创建了一个使用fopen()的程序。 For Ex:-例如:-

int main() {
    FILE* check=NULL;
    check=fopen("C:\\Files\\open.txt","rb");
    if(check==NULL)
    {
        cout<<"Error";
    }
    else
    {
        //do something
    }
    
}

Now, in the above program windows path is working properly ie "C:\\\\Files\\\\open.txt" but when i try to execute the same program in wsl(linux) by changing the path to /mnt/c/Files/open.txt , I am getting error.现在,在上面的程序中,windows 路径工作正常,即"C:\\\\Files\\\\open.txt"但是当我尝试通过将路径更改为/mnt/c/Files/open.txt在 wsl(linux) 中执行相同的程序时/mnt/c/Files/open.txt ,我收到错误。 I am not sure if setting up path this way is the standard procedure for fopen() in linux.我不确定以这种方式设置路径是否是 linux 中fopen()的标准程序。 Please suggest me something to overcome this error.请给我建议一些东西来克服这个错误。

Try adding perror("fopen") to the main function and please share the output.尝试将perror("fopen")到主函数中,请分享输出。 It is difficult to answer this question without the output.没有输出就很难回答这个问题。

I think the problem may be: You don't have permission to access /mnt or no such file or that file doesn't have read permission... etc.我认为问题可能是:您无权访问/mnt或没有此类文件或该文件没有读取权限...等。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM