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

时间:2013-07-24 12:23:08

标签: c++ visual-c++ fopen file-handling

我正在尝试将缓冲区输出到位于我桌面的文件“z.txt”中。我在win32中进行操作(visual c ++) 我这样做的语法是 -

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

            }

任何人都可以请知道为什么会这样做???

2 个答案:

答案 0 :(得分:1)

如果您查看official reference of errors,则会看到错误13为EACCESS,表示您无权写入该文件。

您需要更改文件权限,以便您可以写入文件,当然也可以写文件夹。

答案 1 :(得分:0)

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

相关问题