Advertisement

C++——文件操作

阅读量:

一、撰写文件

例如:

复制代码
 #include<iostream>

    
 #include<fstream>
    
 using namespace std;
    
 //写文件
    
  
    
 void test1()
    
 {
    
 	//创建一个对象
    
 	ofstream ofs;
    
 	ofs.open("text.txt", ios::out);
    
 	ofs << "张三"<< endl;
    
 	ofs << "男" << endl;
    
 	ofs << "18" << endl;
    
 	ofs.close();
    
 }
    
 int main()
    
 {
    
 	test1();
    
 	system("pause");
    
 	return 0;

全部评论 (0)

还没有任何评论哟~