本文整理汇总了C++中Folder::getSize方法的典型用法代码示例。如果您正苦于以下问题:C++ Folder::getSize方法的具体用法?C++ Folder::getSize怎么用?C++ Folder::getSize使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Folder
的用法示例。
在下文中一共展示了Folder::getSize方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: folderTest
string folderTest()
{
vector<pair<Folder *, int>> folds;
vector<File*> fls;
Folder * f = new Folder("test");
f->getAllFoldersRecursively(folds);
if(folds.size() > 1) return "found folders in empty folder";
f->getAllFilesRecursively(fls);
if(fls.size()) return "files found in empty folder";
File * file = new File();
f->addFile(file);
fls.clear();
f->getAllFilesRecursively(fls);
if(fls.size() != 1) return "file count mismatch";
if(f->getSize() != file->getSize()) return "file size mismatch";
Folder * f2 = new Folder("test2");
if(!f->addFolder(f2)) return "addfolder failed";
folds.clear();
f->getAllFoldersRecursively(folds);
if(folds.size() != 2) return "folder count mismatch";
File * file2 = new File();
f2->addFile(file2);
fls.clear();
f->getAllFilesRecursively(fls);
if(fls.size() != 2) return "file count mismatch2";
if(f->getSize() != file->getSize() + file2->getSize()) return "file size mismatch2";
f->removeFile(file->getName());
delete file;
fls.clear();
f->getAllFilesRecursively(fls);
if(fls.size() != 1) return "file count mismatch3";
if(f->getSize() != file2->getSize()) return "file size mismatch3";
f->removeFolder(f2->getName());
delete f2;
folds.clear();
f->getAllFoldersRecursively(folds);
if(folds.size() != 1) return "folder count mismatch2";
delete f;
return "";
}
示例2: main
int main()
{
File* file1 = new File("a.txt", 10); // 파일은 자신의 크기가 있습니다.
File* file2 = new File("b.txt", 20);
File* file3 = new File("c.txt", 30);
Folder* root = new Folder("ROOT"); // 폴더는 자신의 크기가 없습니다.
Folder* folder1 = new Folder("A");
Folder* folder2 = new Folder("B");
folder1->add(file1);
folder2->add(file2);
root->add(file3);
root->add(folder1);
root->add(folder2);
cout << file1->getSize() << endl; // 파일은 크기를 구할 수 있습니다.
cout << root->getSize() << endl; // 폴더도 크기를 구할 수 있습니다.
// print hierarchy
cout << endl;
root->print();
}