本文整理汇总了C++中TreeNode::content方法的典型用法代码示例。如果您正苦于以下问题:C++ TreeNode::content方法的具体用法?C++ TreeNode::content怎么用?C++ TreeNode::content使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TreeNode
的用法示例。
在下文中一共展示了TreeNode::content方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: file
Tree<_DATA>& Tree<_DATA>::
save_this(const char* dir) {
char path[SIZEOF_PATH], * filename;
std::strcpy(path, dir);
std::size_t dir_len = std::strlen(path);
std::size_t file_len;
if (dir_len > 0 && (path[dir_len - 1] != '/' && path[dir_len - 1] != '\\'))
path[dir_len++] = '/';
filename = path + dir_len;
file_len = SIZEOF_PATH - dir_len;
std::strcpy(filename, "Tree");
std::ofstream file(path);
if (!file.is_open()) {
std::cerr << "\nFailed opening file: " << path << std::endl;
return *this;
}
unsigned long node_num = 0;
file << std::setw(16) << std::setfill('0') << node_num << ".node"
<< " # root" << std::endl;
file.close();
std::queue<TreeNode*> node_pointer;
std::queue<unsigned long> node_name;
std::queue<unsigned long> node_parent_name;
node_pointer.push(root_);
node_name.push(node_num);
node_parent_name.push(0);
while (!node_pointer.empty()) {
TreeNode* node = node_pointer.front();
unsigned long name = node_name.front();
unsigned long parent_name = node_parent_name.front();
std::snprintf(filename, file_len, "%016lu.node", name);
file.open(path);
if (!file.is_open()) {
std::cerr << "\nFailed opening file: " << path << std::endl;
return *this;
}
file << std::setw(16) << std::setfill('0') << parent_name
<< ".node # parent\n"
<< node->depth() << " # depth\n";
unsigned int n_child = node->num_of_children();
file << n_child << " # number of children\n";
if (n_child) {
TreeNode** child = node->children();
for (unsigned int i = 0; i < n_child; ++i) {
node_pointer.push(child[i]);
node_name.push(++node_num);
node_parent_name.push(name);
file << std::setw(16) << std::setfill('0') << node_num
<< ".node # child " << i << "\n";
}
}
file << node->content();
file.close();
node_pointer.pop();
node_name.pop();
node_parent_name.pop();
}
return *this;
}