#include <iostream> #include <fstream> #include <string> #include <conio.h> using namespace std; void writeFileDemo5() { ofstream writeFile("writeFile7.txt",std::ios::app); if (!writeFile.is_open()) { cout << "Create writeFile2.txt failed! " << endl; return; } char str[10000]; char ch; while ((ch=_getch())!=27) { cin.getline(str, 10000); writeFile << str << endl; } cout << "Over" << endl; writeFile.close(); cout << "Finished!" << endl; }
#include <iostream> #include <ostream> #include <istream> #include <fstream> #include <conio.h> using namespace std; void ostreamDemo6() { ofstream writeFile; writeFile.open("WriteFile6.txt", std::ios_base::app); if (writeFile.is_open()) { char str[10000]; char ch; while (1) { cin.getline(str, 10000); ch = _getch(); if (ch != 27) { writeFile << str << endl; } else { cout << "Over" << endl; break; } } } writeFile.close(); cout << "Finished" << endl; }