-
Notifications
You must be signed in to change notification settings - Fork 939
Expand file tree
/
Copy pathmain.cpp
More file actions
executable file
·45 lines (37 loc) · 1.37 KB
/
main.cpp
File metadata and controls
executable file
·45 lines (37 loc) · 1.37 KB
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
45
#include "../exercise.h"
#include <filesystem>
#include <fstream>
// READ: `std::filesystem` <https://zh.cppreference.com/w/cpp/filesystem>
int main(int argc, char **argv) {
namespace fs = std::filesystem;
// TODO: 为下列 ASSERT 填写正确的值
{
// 获取当前路径
fs::path current_path = fs::current_path();
ASSERT(?, "填入 current_path.empty() 或者 !current_path.empty()");
}
{
fs::path test_dir = "test_directory";
fs::create_directory(test_dir);
ASSERT(?, "填入 fs::exists(test_dir) 或者 !fs::exists(test_dir)");
fs::remove(test_dir);
ASSERT(?, "填入 fs::exists(test_dir) 或者 !fs::exists(test_dir)");
}
{
fs::path test_file = "test_file.txt";
std::ofstream ofs(test_file);
ofs << "Hello, filesystem!";
ofs.close();
ASSERT(?, "填入 fs::exists(test_file) 或者 !fs::exists(test_file)");
std::ifstream ifs(test_file);
std::string content;
std::getline(ifs, content);
ASSERT(content == ?, "File content should match the written content");
ifs.close();
auto file_size = fs::file_size(test_file);
ASSERT(file_size == ?, "File size should be ?");
fs::remove(test_file);
ASSERT(!fs::exists(test_file), "File should not exist after removal");
}
return 0;
}