intmain() { // The default behavior when copying directories is the non-recursive copy: the files are copied, but not the subdirectories std::experimental::filesystem::copy("dir1", "dir2");
// While with copy_options::recursive, the subdirectories are also copied, with their content, recursively. std::experimental::filesystem::copy("dir1", "dir3", std::experimental::filesystem::copy_options::recursive);
// g++ std-filesystem-copy2.cpp -o a.out -std=c++11 -lstdc++fs #include<iostream> #ifdef CXX17 // if this is C++17 #include<filesystem> namespace fs = std::filesystem; #else #include<experimental/filesystem> namespace fs = std::experimental::filesystem; #endif
intmain() { // The default behavior when copying directories is the non-recursive copy: the files are copied, but not the subdirectories fs::copy("dir1", "dir2");
// While with copy_options::recursive, the subdirectories are also copied, with their content, recursively. fs::copy("dir1", "dir3", std::experimental::filesystem::copy_options::recursive); }
如果來源檔 dir1 不存在會怎樣? 會發生core dumped,如下列輸出:
1 2 3
terminate called after throwing an instance of 'std::experimental::filesystem::v1::__cxx11::filesystem_error' what(): filesystem error: cannot copy: No such file or directory [dir1] [dir2] Aborted (core dumped)
print('cpu count: {}'.format(psutil.cpu_count())) for x in range(10): print('cpu percent: {}'.format(psutil.cpu_percent(interval=0.3)))
輸出:
1 2 3 4 5 6 7 8 9 10 11
cpu count: 4 cpu percent: 18.2 cpu percent: 16.4 cpu percent: 18.0 cpu percent: 18.5 cpu percent: 19.8 cpu percent: 17.6 cpu percent: 18.0 cpu percent: 17.2 cpu percent: 16.9 cpu percent: 18.6