我正在尝试使用 Visual C++ 将缓冲区输出到文件。我这样做的代码是-
FILE *stream;
stream=fopen("C:\\Users\\sshekha\\Desktop\\z.txt","r");
//I also tried with "w" mode
//the differencein behavious on executing these two is that when it is in read mode it
//executes the else condition in the code below whereas in "w" mode it executes the "if"
// condition,
//moreover even if i change the path it don't execute the "else" condition-that means this path
//is effective to the code. and the another surprising thing is when i open the file manually
// and then run the code with "r" mode it still executes the "else" part (which it shouldn't
// because the file is already open.)
if( stream == 0 )
{
MessageBox(m_hwndPreview,L" the file is not opened ",L"BTN WND",MB_ICONINFORMATION);
}
else
{
MessageBox(m_hwndPreview,L" the file is opened ",L"BTN WND",MB_ICONINFORMATION);
int check=fputs (HtmlFileContents,stream);
fclose(stream);
return 0;
}
我尝试使用不同的模式检查结果,以了解正在发生的事情。当我调试它时,我得到(在读取模式下)的值:
流 = 0x000000005c5c76f0 { _ptr=0x0000000000000000 _cnt=0 _base=0x0000000000000000 ...}
我不知道它 gib=ves 错误的指针,即使这样它也会转到循环的 else 部分。为什么 ?
并处于写入模式
流 = 0x0000000000000000 {_ptr=??? _cnt=??? _base=??? ...}
所以转到循环的 if 部分。
此外,我的路径是正确的,并且我有足够的权限来完成我希望完成的任务。但是为什么它给出了错误的指针?为什么我有这些奇怪的流值,我应该怎么做才能将缓冲区的内容复制HtmlFileContents
到z.txt
?有任何想法吗 ?