1 | #include <iostream> |
---|
2 | #include <string> |
---|
3 | #include <fstream> |
---|
4 | #include <regex> |
---|
5 | |
---|
6 | using namespace std; |
---|
7 | |
---|
8 | int main() |
---|
9 | { |
---|
10 | ifstream inp; |
---|
11 | ofstream out; |
---|
12 | regex leading_spaces("[[:space:]]*(.+)"); |
---|
13 | string line; |
---|
14 | inp.open("spaces.txt"); |
---|
15 | out.open("clear_spaces.txt"); |
---|
16 | if(inp.is_open()) |
---|
17 | { |
---|
18 | while(inp.good()) |
---|
19 | { |
---|
20 | getline(inp,line); |
---|
21 | smatch result; |
---|
22 | regex_token_iterator<string::const_iterator> i(line.begin(), line.end(), leading_spaces, -1); |
---|
23 | regex_search(line,result,leading_spaces); //search for leading spaces |
---|
24 | if(result[1].str().length()>0) //ignore empty lines |
---|
25 | { |
---|
26 | out<<result[1].str()<<endl; //write on disk the cleaned line |
---|
27 | } |
---|
28 | } |
---|
29 | } |
---|
30 | inp.close(); |
---|
31 | out.close(); |
---|
32 | return(0); |
---|
33 | } |
---|