C++ 实验七

#include <iostream>
#include <fstream>
using namespace std;

int main(){
 ofstream file;
 file.open("E:\\text.txt");
 file << "已成功写入文件!" << endl;
 file.close();
 return 0;
} 
11-3

#include <iostream>
#include<string>
#include <fstream>
using namespace std;

int main(){
    string temp;
 ifstream file;
 file.open("E:\\text.txt");
 while (getline(file, temp) ){     //每当读取一行的时候
     cout << temp<<endl;    //输出那一行的内容(已经知道是字符串了)
 };
 file.close();
 system("pause");
 return 0;
} 
11-4

猜你喜欢

转载自www.cnblogs.com/nuo26/p/9175784.html