实例154 使用 流类库输出一个文件

版权声明:转载商用请通知本人 https://blog.csdn.net/qq_41076577/article/details/84494038

定义输出流对象fout,先打开文件out.txt,再判断是否成功打开,输出Hello World。代码如下:

​
#include<iostream>
#include<fstream>
using namespace std;
int main(){
	ofstream fout;
	fout.open("out.txt");              //打开文件     
	if(fout.fail())                    //如果打开失败 
	    cout<<"out.txt 文件打开失败"<<endl;
	else
	     fout<<"Hello World"<<'\n';     //输出 
	
}

​

猜你喜欢

转载自blog.csdn.net/qq_41076577/article/details/84494038
154
今日推荐