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!\n";
 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 }

 

posted @ 2014-04-01 21:29  秋月的私语  阅读(152)  评论(0编辑  收藏  举报