注册 登录
编程论坛 C++教室

请教一个关于文件打开的问题

YCVSCY 发布于 2008-07-12 21:46, 658 次点击
//Visual 6.0环境下
# include <iostream>
# include <fstream>
using namespace std;

int main ()
{
    ofstream outfile;
    outfile.open("f1.dat",ios::out); //为什么我把它改成("e:\c++\f1.dat",ios::out)
    if(!outfile)                                            //注:目录没有错。
        cout<<"open error !"<<endl;
    else
        cout<<"open good !"<<endl;
    outfile.close();
    return 0;

}
4 回复
#2
linren2008-07-12 22:15
路径因该写成这样:
e:\\c++\\f1.dat
#3
linren2008-07-12 23:21
写成这样:
e:/c++/f1.dat

写成这样:
e://c++//f1.dat

写成这样:
e:\\c++/f1.dat

都是可以的……
#4
YCVSCY2008-07-13 20:58
谢谢楼上两位了,两位的方法都很好!!
#5
水中无月2008-07-13 21:13
“\\”
前面那个杠是转义字符,后面的才是真正的斜杠
1