码迷,mamicode.com
首页 > 其他好文 > 详细

p307

时间:2020-02-05 13:21:10      阅读:78      评论:0      收藏:0      [点我收藏+]

标签:space   info   打开文件   names   ifstream   img   fstream   lse   mic   

源程序:

#include <iostream>
#include <fstream>
using namespace std;
int main()
{
ifstream inFile("c:\\tmp\\test.txt", ios::in); //声明对象inFile并调用构造函数
if (inFile)
{
cout << "成功打开文件:c:\\tmp\\test.txt\n";
inFile.close();
}
else
cout << "打开文件失败:c:\\tmp\\test.xt\n";
ofstream outFile("test2.txt", ios::out); //声明对象outFile并调用构造函数
if (!outFile)
cout << "error1" << endl;
else
{
cout << "成功打开文件:test1.txt\n";
outFile.close();
}
fstream outFile2("tmp\\test2.txt", ios::out | ios::in); //声明对象outFile2并调用构造函数
if (outFile)
{
cout << "成功打开文件:tmp\\test2.txt\n";
outFile.close();
}
else
cout << "error2" << endl;
system("pause");
return 0;
}

运行结果:

技术图片

 

p307

标签:space   info   打开文件   names   ifstream   img   fstream   lse   mic   

原文地址:https://www.cnblogs.com/duanqibo/p/12263308.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!