Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- #include <stdlib.h>
- #include <fstream>
- #include <string>
- #include <sstream>
- using namespace std;
- string removeSpaces(string s);
- int main()
- {
- fstream fin("text1.txt", ios::in | ios::out);
- //string a;
- if (!fin)
- {
- cout << "Can't open file" << endl;
- }
- stringstream strs;
- strs << fin.rdbuf();
- fin.seekp(0);
- string line;
- while (getline(strs, line))
- {
- if (!line.empty())
- {
- line = removeSpaces(line);
- fin << line << std::endl;
- }
- }
- fin.close();
- system("pause");
- return 0;
- }
- string removeSpaces(string s)
- {
- for (int j = 0; j < s.length(); j++)
- {
- if (s[j] == ' ')
- {
- while (s[j + 1] == ' ') s.erase(j + 1, 1);
- }
- }
- return s;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement