使用C++编程为什么无法打开文件

来源:百度知道 编辑:UC知道 时间:2024/06/07 03:52:29
#include<stdio.h>
main()
{
FILE *fp;
、 fp=fopen("d:\\123.txt","w+");
if(fp==NULL)
{
printf(" 无法打开 c:\\123 file!");

}
return 0;
}
编译和运行的时候都没有错误,但123.txt始终没有打开
这是为什么啊?

我想你可能理解错了fopen函数的作用了,它不是像用记事本一样打开这个文件进行编辑,而是在内存中打开,在内存中操作。如果你想打开这个文件进行编辑,可以用ShellExecute函数,它的原型是:
HINSTANCE ShellExecute( HWND hwnd,
LPCTSTR lpOperation,
LPCTSTR lpFile,
LPCTSTR lpParameters,
LPCTSTR lpDirectory,
INT nShowCmd
);
不过要加上shellapi.h头文件,这属于windows程序里的了。具体函数参数的说明可参看MSDN。

#include<stdio.h>
main()
{
FILE *fp;
、 fp=fopen("d:\\123.txt","w+"); //这里是d://123.txt
if(fp==NULL)
{
printf(" 无法打开 c:\\123 file!"); //而这里又是c:\\

}
return 0;
}
应该就是这个问题吧!