#include <iostream> #include <fstream> using namespace std; int main(){ ofstream file; file.open("E:\\text.txt"); file << "已成功写入文件!" << endl; file.close(); return 0; }
#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; }