哪里出的有关问题?大家帮忙看看
哪里出的问题?大家帮忙看看
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
ofstream myfile;
myfile.open("c:\\1.txt",ios::out|ios::app,0);
if(!myfile)
{
cout<<"文件创建失败,磁盘不可写或者文件为只读!";
system("pause");
exit(1);
}
myfile<<"这不仅仅是一个测试"<<endl<<"Bring me the encourage."<<endl;
myfile.close();
}
编译成功,生成失败,什么情况?(c:\\1.txt我已经建好并设置好访问权限,测试环境是win7+vs2012)
------解决方案--------------------
参数参考
Type of sharing allowed.
_SH_DENYNO
Permits read and write access.
_SH_DENYRD
Denies read access to the file.
_SH_DENYRW
Denies read and write access to the file.
_SH_DENYWR
Denies write access to the file.
0在vs里未定义
------解决方案--------------------
myfile.open("C:\\1.txt",ios::out
------解决方案--------------------
ios::app); 也可以
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
ofstream myfile;
myfile.open("c:\\1.txt",ios::out|ios::app,0);
if(!myfile)
{
cout<<"文件创建失败,磁盘不可写或者文件为只读!";
system("pause");
exit(1);
}
myfile<<"这不仅仅是一个测试"<<endl<<"Bring me the encourage."<<endl;
myfile.close();
}
编译成功,生成失败,什么情况?(c:\\1.txt我已经建好并设置好访问权限,测试环境是win7+vs2012)
------解决方案--------------------
#include <iostream>
#include <fstream>
#include <share.h>
using namespace std;
int main()
{
ofstream myfile;
myfile.open("D:\\1.txt",ios::out
------解决方案--------------------
ios::app, _SH_DENYNO); // 这里需要调整
if(!myfile)
{
cout<<"文件创建失败,磁盘不可写或者文件为只读!";
system("pause");
exit(1);
}
myfile<<"这不仅仅是一个测试"<<endl<<"Bring me the encourage."<<endl;
myfile.close();
}
参数参考
Type of sharing allowed.
_SH_DENYNO
Permits read and write access.
_SH_DENYRD
Denies read access to the file.
_SH_DENYRW
Denies read and write access to the file.
_SH_DENYWR
Denies write access to the file.
0在vs里未定义
------解决方案--------------------
myfile.open("C:\\1.txt",ios::out
------解决方案--------------------
ios::app); 也可以