Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <cstdlib>
- #include <cstring>
- #include <windows.h>
- using namespace std;
- int main(int argc, char* argv[])
- {
- int spacesToRemove = -1;
- if (argc == 1 || argc > 3)
- {
- cout << "Please provide a directory to the file, in which you want to remove unwanted spaces.\n"
- << "You can do this in two ways:\n"
- << "1. Drag .txt file onto the executable of this program;\n"
- << "2. Open cmd and provide a directory to this program's executable,\n"
- << "then after space a directory to your .txt file, optionally you can provide\n"
- << "a number of spces to remove, i.e.:\n"
- << "C:\\RemoveSpaces.exe C:\\MyTxtFile.txt 5\n";
- system("pause");
- return 1;
- }
- else if (argc == 2)
- {
- cout << "Please provide a number of spaces to remove: ";
- cin >> spacesToRemove;
- }
- else if (argc == 3)
- {
- spacesToRemove = atoi(argv[2]);
- }
- ifstream file;
- ofstream newFile;
- file.open(argv[1]);
- newFile.open(strcat(argv[1], "new"));
- string str;
- while (true)
- {
- getline(file, str);
- if (str.length() > spacesToRemove)
- {
- str = str.substr(spacesToRemove);
- }
- newFile << str << '\n';
- if (file.eof())
- {
- break;
- }
- }
- newFile.close();
- file.close();
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement