使用fopen_s将输出重定向到文件

Redirecting output to file using fopen_s

本文关键字:重定向 文件 输出 fopen 使用      更新时间:2023-10-16

我正在尝试将缓冲区输出到桌面上的文件"z.txt"中我这样做的语法是-

  memcpy(HtmlFileContents,&Buffer[location],HtmlFileLength);//i have the contents in HtmlFileContents 
//which i have to display  in the file "z.txt"
                FILE *stream ;
                errno_t err;
                err=fopen_s(&stream, "C:\Users\sshekha\Desktop\z.txt","w");//err gives error 13
// when in write mode but when in read mode it opens the file   
                if( err == 0 )
                {
                    MessageBox(m_hwndPreview,L" the file is opened ",L"BTN WND",MB_ICONINFORMATION);
                }
                else
                {
                    MessageBox(m_hwndPreview,L" the file is not opened ",L"BTN WND",MB_ICONINFORMATION);
            }

有人能说出它为什么这么做吗???

如果您检查错误的官方引用,您会发现错误13是EACCESS,这意味着您无权写入该文件。

你需要更改文件权限,这样你就可以写入它,当然还有文件夹。

您应该检查文件是否在其他地方打开(或者更具体地说,没有正确关闭)。