C++ 文件IO

 1 #include <iostream>
 2 #include <fstream>
 3 using namespace std;
 4 int main(int argc, char *argv[])
 5 {
 6      ofstream fout("D:\a.txt");
 7      fout << "good morning!
";
 8      fout << "1 + 2 = " << 1 + 2 << endl;
 9      fout.close();
10     return 0;
11 }
 1 #include <iostream>
 2 #include <fstream>
 3 #include <string>
 4 using namespace std;
 5 
 6 int main(int argc, char *argv[])
 7 {
 8     string stContent = "";
 9      ifstream fin("D:\a.txt");
10      getline(fin, stContent);
11      cout << "第一行:" + stContent <<endl;
12      getline(fin, stContent);
13      cout << "第二行:" + stContent <<endl;
14     return 0;
15 }
原文地址:https://www.cnblogs.com/autumoonchina/p/3639237.html