C++文件输入和创建

 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 !
";    
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    //写入文件
原文地址:https://www.cnblogs.com/likeghee/p/10739053.html