Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void writeIntegerTobinaryFile(string filePath)
- {
- int inputInteger;
- cin » inputInteger;
- fstream binaryFile(filePath, ios::out | ios :: binary | ios::app);
- binaryFile.write((char*)&inputInteger,sizeof(inputInteger));
- binaryFile.close();
- }
- void readIntegerFromFile(string filePath)
- {
- int outputInteger;
- fstream binaryFile((char*)&outputInteger, sizeof(outputInteger));
- cout « outputInteger « endl;
- binaryFile.close();
- }
- ofstream fout;
- fout.open("file.txt"); // a path to txt file where we'll print out text
- ifstream ifs;
- ifs.open("testfile.txt"); // inital text
- int maxLength; // variable for holding maximum length value
- cout << "enter length ";
- cin >> maxLength;
- string str;
- if (!ifs.is_open()) // statement for testing file existing
- {
- cout << "We couldn't open it";
- }
- else
- {
- cout << "\n File has been successufly opened ";
- char ch;
- while (ifs.get(ch))
- {
- str += ch; //appending char to a string variable
- }
- int counter = 0;
- int start = 0;
- int end = 0;
- for (int i = 0; i < str.length() + 1; i++)
- {
- if (str[i] != ' ')
- {
- counter++;
- if (i == str.length())
- {
- end = i;
- str.erase(str.begin() + start, str.begin() + end);
- break;
- }
- }
- else
- {
- end = i;
- if ((end - start) > maxLength)
- {
- str.erase(str.begin() + start, str.begin() + end);
- i -= end - start;
- }
- start = i;
- end = i;
- counter = 0;
- }
- }
- for (int i = 0; i < str.length(); i++)
- {
- fout << str[i];
- }
- }
- ifs.close();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement