1     #include <fstream>
 2         //头文件
 3     
 4 
 5     ifstream inf;
 6     ofstream ouf;
 7     inf.open("zy4.txt", ios::out);
 8     if (!inf)
 9     {
10         inf.close();
11         ouf.open("zy4.txt");
12         if (ouf)
13             cout << "zy4.txt Created successfully!" << endl;
14     }
15     else
16         cout << "The file is exited !\n";    
17     
18    //创建文件
19 
20 
21     ofstream fout1("zy4.txt");
22     if (!fout1.is_open())
23     {
24         cerr << "无法打开文件 " << "zy4.txt" << endl;
25         exit(0);
26     }
27     fout1 << S << endl;
28     fout1.close();
29    //写入文件

 

posted on 2019-04-19 21:49  likeghee  阅读(343)  评论(0编辑  收藏  举报