-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathmain.cpp
More file actions
44 lines (36 loc) · 878 Bytes
/
main.cpp
File metadata and controls
44 lines (36 loc) · 878 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include <iostream>
#include <thread>
#include <vector>
#include <filesystem>
#include <algorithm>
#include <execution>
#include <regex>
#include "search.h"
using namespace std;
int main() {
string path;
cout <<"Enter file Path: ";
cin >> path;
vector<string> files;
for (const auto& entry : filesystem::directory_iterator(path)) {
files.push_back(entry.path());
};
string word;
cout << "Enter word/pattern to search: ";
cin >> word;
regex pattern;
try{
pattern = regex(word);
} catch (const regex_error& e) {
cerr << "Invalid regex pattern: " << e.what() << endl;
return 1;
}
vector<thread> threads;
for (const auto& file : files) {
threads.push_back(thread(searchInFile, file, ref(pattern)));
}
for (auto& t : threads) {
t.join();
}
return 0;
}