#include <iostream>#include <string>#include <fstream> using namespace std; int main () { // Uncomment to createdata.exe file // ofstreamofs("data.exe", ios_base::binary | ios_base::out); // if(ofs.is_open()) { // ofs << "Lorem ipsum dolor sit amet, consectetur adipiscing elit."; // ofs.close(); // } stringparagraph; // paragraph from file stringnewParagraph = ""; // new paragraph // Reads string fromdata file ifstream ifs("data.exe", ios_base::binary | ios_base::in); if (ifs.is_open()) { getline(ifs, paragraph); ifs.close(); } cout << paragraph << endl; // Converts string for (int i = 0; i < paragraph.length(); i++) { if (!isspace(paragraph[i])) { newParagraph.push_back(paragraph[i]); } else { if (!isspace(paragraph[i - 1])) { newParagraph.push_back(' '); } } } // Outputs string todata file ofstream newOfs("data.exe", ios_base::binary | ios_base::out); if (newOfs.is_open()) { newOfs << newParagraph; newOfs.close(); } cout << newParagraph; return 0;}
Comments