forked from WHUCodingAndOpen/OpenCourseResources
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path源.cpp
More file actions
29 lines (24 loc) · 767 Bytes
/
Copy path源.cpp
File metadata and controls
29 lines (24 loc) · 767 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
#define _CRT_SECURE_NO_WARNINGS 1
#include <iostream>
#include <filesystem>
#include <fstream>
using namespace std;
int main() {
string folderPath = "D:\\Setup\\Files\\Files";
string targetContent = "MSC2023";
for (const auto& entry : filesystem::directory_iterator(folderPath))
{
if (entry.path().extension() == ".txt")
{
ifstream file(entry.path());
string content((istreambuf_iterator<char>(file)), istreambuf_iterator<char>());
file.close();
if (content == targetContent)
{
cout << "The path to the target file: \n" << entry.path().string() << endl;
break;
}
}
}
return 0;
}