使用fopen_s将输出重定向到文件
Redirecting output to file using fopen_s
我正在尝试将缓冲区输出到桌面上的文件"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
,这意味着您无权写入该文件。
你需要更改文件权限,这样你就可以写入它,当然还有文件夹。
您应该检查文件是否在其他地方打开(或者更具体地说,没有正确关闭)。
相关文章:
- 获取通过重定向传入的输入文件的名称?
- 写入文件 a.txt,而终端重定向到文件 b.txt
- 将 clangd stderr 重定向到文件而不是控制台
- 是否可以将子进程的 stdout 重定向到父进程中的另一个文件?
- 重定向输入和输出时如何处理主文件I/O?
- 使用重定向命令从 stdin 读入的字符串"<"输入文件未正确附加
- 可以将Boost消息队列文件重定向到用户指定的位置
- 如何使用PHP将上传到本地主机的一个html文件重定向到磁盘上的另一个html文档
- 尝试将 std::cerr 重定向到文件时出现访问冲突异常
- 重定向到文件的C ++ COUT比使用Ofstream慢
- 将 Tcl 中的命令输出重定向到文件时,文件以 DOS 格式生成
- 将 c++ 程序语法错误重定向到窗口中的文件
- 如何在没有任何缓冲区的情况下将 stderr 重定向到文件?
- 将 ffmpeg 控制台输出重定向到C++中的字符串或文件
- Win32 GUI C(++) 应用将标准输出和标准输出重定向到磁盘上的同一文件
- 即使可执行文件的输入是从文件重定向的,如何强制从终端输入?
- C++输入重定向导致文件参数工作时出错
- C++ vector<pair<int,int>> std::all_of() 函数问题(重定向到头文件)
- 重定向文件访问
- Boost.IOStreams:如何使用"rdbuf"正确重定向文件流?